I had to rewrite part of a programme to use XMLReader to select parts of an XML file for processing.
Take this simplified XML as an example:
[Ignore the SimpleXML solution and look down at the XMLReader one]
I would suggest using the SimpleXMLElement::xpath method.
http://php.net/manual/en/simplexmlelement.xpath.php
$xml = new SimpleXMLElement($xml_string);
/* Search for */
$result = $xml->xpath("/odds/sport/region/group/event/bet");
$result will contain all children of 'bet' note.
// XMLReader solution **********************
$reader = new XMLReader;
$reader->open('file.xml');
$parent_element = null;
while($reader->read()) {
$selectionid = $reader->getAttribute('selectionid');
if ($selectionid == '52411062.1' ) {
// use the parent of the node with attribute 'selectionid' = '52411062.1'
$node = $parent_element;
var_dump($node);
break;
}
elseif ($reader->name === 'bet') { )
{
// store parent element
$parent_element = new SimpleXMLElement($reader->readOuterXML());
}
}