Accessing XML namespace elements via simplexml_import_dom and XMLReader

We’ve got a script that parses large XML imports and we’re adding support for a few new formats one of which uses namespaces. While SimpleXML has no issue reading these normally, we haven’t been able to figure how to do things properly while working with XMLReader [these are huge files so we need to chunk through them].

Example Code:

$z = new XMLReader;
$doc = new DOMDocument('1.0','UTF-8');
while ($z->read() && $z->name !== 'product');
while ($z->name === 'product'){
  $prodinfo = simplexml_import_dom($doc->importNode($z->expand(), true));



XML items look something like

<title>This is an item</title>

We did try the children approach directly but it’s duplicating the same namespace results for every record.

$foo = $prodinfo->children(‘’);

Any ideas on how to blend the children request with the XMLreader loop?