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;
$z->open('test.xml');
$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));

  print_r($prodinfo);
  $z->next('product');
  continue;

}

XML items look something like

<product>
<title>This is an item</title>
<abt:price>199.99</abt:price>
<abt:quantity>5</abt:quantity>
</product>

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

$foo = $prodinfo->children(‘http://www.somename.com/’);

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