Jump to content

XMLReader, DOMXPath


rossh

Recommended Posts

Hi

 

I have the following code to filter xml data.  I'm now able to query the xml file, but the results are not well formed, so i can't output specific elements.  Does anyone know how to return element names and values from DomXpath?

 

<?php
$reader = new XMLReader();
$reader->open('include/staff.xml');

while ($reader->read()){
	switch($reader->nodeType){
		case(XMLREADER::ELEMENT):
			if($reader->localName === 'staff'){
				$node = $reader->expand();
				$dom = new DomDocument();
				$dom->formatOutput = true;
				$n = $dom->importNode($node, true);
				$dom->appendChild($n);
				$xp = new DomXpath($dom);
				$res = $xp->query("//staff/member[groups='HR']");
			}
	}
}
foreach($res as $staff){
	echo $staff->nodeValue;
}
?>

Link to comment
https://forums.phpfreaks.com/topic/194017-xmlreader-domxpath/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.