XPath PHP API - Context Query
xpath-api-context.php:
<?php
//load xml document
$dom = new DomDocument();
$dom->load("examples/books.xml");
//create DOMXPath object
$xpath = new Domxpath($dom);
//get all books
$result = $xpath->query("//book");
//get first found book
$firstBook = $result->item(0);
//$query for the title of the $firstBook
$result = $xpath->query("title", $firstBook);
//loop through the result (it's a NamedNodemap..)
foreach ($result as $title) {
print $title->nodeValue. "\n";
}
XPath PHP API - Context Query
© copyright 2004 Bitflux GmbH