XPath DOM Query : xpath « XML « PHP

XPath DOM Query


 <title>XPath DOM Query</title>



$dom = new DomDocument();  
$dom -> load( "food.xml" );

$xp = new DomXPath( $dom );  

$fruits = $xp -> query( "/food/fruit/item" );
foreach($fruits as $node)
  echo( "<li>" . $node -> textContent . "</li>" );
echo( "</ul>" );



Related examples in the same category

1.Combine it with an XPath search
3.Using XPath and DOM
4.Using XPath and SimpleXML in a basic example
5.Using XPath with DOM in a basic example
6.Using XPath with SimpleXML in a more complicated example
7.XPath can be used to filter your results according to any values
8.Searching and Filtering with XPath