load($url); # setup xpath object $xpath = new DOMXPath($xmlDoc); $queries = array( "//author", "//book[year>2004]/author[contains(.,'De') or contains(.,'J')]", "//book[year>2004]/author[contains(.,'De')]", # the following two are NOT the same "//book/author[contains(.,'J')]", "//book[contains(author,'J')]/author", "//book[contains(author,'J')]", # the following two are equivalent "//book/title[contains(.,'Ital')]", "//book[contains(title,'Ital')]/title", "/bookstore/book[title/@lang='en'][price<40]", # the following are equivalent "/bookstore/book/title[../title/@lang='en']", "/bookstore/book/title[@lang='en']", "//title[@lang='en']", "//book/title[@lang='en']", "//book[title/@lang='en']/title", # the following is a typo "//book[@lang='en']/title", "//book[//price<30]/title", "//book[price<30]/title", "//book[price<30]", "//book/title", "//book", "/bookstore/book[200]", "/book", "/bookstore/book[2]", "/bookstore/book", ); # # LOOP OVER ALL XPath expressions: # foreach ($queries as $query) { print <<evaluate($query); foreach ($nodelist as $one) { print "NODE:\t".$one->getNodePath()."\n"; print "VALUE:\t".$one->nodeValue."\n\n"; } print "\n\n\n\n"; } echo "\n\n


\n\n\n"; echo $xmlDoc->saveXML(); ?>