I am trying to read a large xml file (about 40 MB) and use this data to update the db of my application.
I seem to have found a good compromise in terms of elapsed time / memory using XMLReader and simplexml_import_dom (), but I cannot get the value of the attributes with a colon in their name ... for example <g:attr_name> .
If I just use the $ reader-> read () function for each "product" node, I can extract the value as the value of $ reader->, but if I expand () the node and copy it using $ doc-> importNode, these attributes are ignored .
$reader = new XMLReader(); $reader->open(__XML_FILE__); $doc = new DOMDocument; while ($reader->read()) { switch ($reader->nodeType) { case (XMLREADER::ELEMENT): if($reader->localName=="product"){ $node = simplexml_import_dom($doc->importNode($reader->expand(), true)); echo $node->attr_name."<br><br>"; $reader->next('product'); } } }
I probably missed something ... any advice would really be appreciated!
Thanks.
source share