XPath DOM Query : xpath « XML « PHP






XPath DOM Query

 
<html>

<head>
 <title>XPath DOM Query</title>
</head>

<body>


<?php

$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>" );

?>

</body>
</html>
  
  








Related examples in the same category

1.Combine it with an XPath search
2.xpath.php
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