I am parsing through a XML file that’s about 12mb big. I need to parse through the entire file and store what I find necessary in a MySQL database.
I am turning the XML file into an array. Then I parse through the array and store the values.
This works fine when the XML is really small, but it just stops behaving right when I run my 12mb file.
I tried multiple functions that convert XML to array that I found online and none of them work.
This is a common error I got with two different XML to array functions I found online:
Fatal error: [] operator not supported for strings
I am using SimpleXML, is there a better way of resolving this? Are there any libraries other than SimpleXML that are powerful enough to handle large XML files?
I have this now:
$z = new XMLReader;
$z->open('feedfetch.xml');
$doc = new DOMDocument;
while ($z->read() && $z->name !== 'collection');
while ($z->name === 'collection')
{
$node = simplexml_import_dom($doc->importNode($z->expand(), true));
var_dump($node[0]);
exit;
$z->next('collection');
}
Do you see my var dump? It echoes a bunch of XML objects, but I don’t know how to get to the actual node with the data?
Switch from using SimpleXML to XMLReader when working with large XML files. This is a Pull parser that will not load the entire file into memory to process it.