Which is the best way to parse an XML file in PHP ?
First
Using the DOM object
//code
$dom = new DOMDocument();
$dom->load("xml.xml");
$root = $dom->getElementsByTagName("tag");
foreach($root as $tag)
{
$subChild = $root->getElementsByTagName("child");
// extract values and loop again if needed
}
Second
Using the simplexml_load Method
// code
$xml = simplexml_load_string("xml.xml");
$root = $xml->root;
foreach($root as $tag)
{
$subChild = $tag->child;
// extract values and loop again if needed
}
Note : These are the two I am aware of. If there are more fill in.
Wanted to know which method is the best for parsing huge XML files, also which method is the fastest irrespective of the way the method needs to be implemented
Size will be varying from 500KB to 2MB. The parser should be able to parse small as well as large files in the least amount of time with good memory usage if possible.