note 89953 deleted from simplexmlelement.xpath by danbrown
| From: | danbrown@php.net | Date: | Wed, 28 Oct 2009 16:05:59 +0000 |
| Subject: | note 89953 deleted from simplexmlelement.xpath by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-162188@lists.php.net to get a copy of this message | ||
Note Submitter: jchris dot fillionr at kitware dot com
----
An other example:
<?php
$string = <<<XML
<a>
<b>
<c>
<d>Apple</d>
<d>Banana</d>
</c>
<e>
<f>Kiwi</f>
</e>
</b>
</a>
XML;
//$string = file_get_contents("test.xml");
$xml = new SimpleXMLElement($string);
/* Search for <a><b><c> */
$result = $xml->xpath('/a/b/c/d');
while(list( , $node) = each($result)) {
echo '/a/b/c/d: ',$node,"\n";
}
/* Relative paths ... : DO NOT WORK */
$result = $xml->xpath('c/d');
while(list( , $node) = each($result)) {
echo 'c/d: ',$node,"\n";
}
/* Relative paths ... : WORK */
$result = $xml->xpath('b/c/d');
while(list( , $node) = each($result)) {
echo 'b/c/d: ',$node,"\n";
}
/* Relative paths ... : WORK */
$result = $xml->xpath('//c/d');
while(list( , $node) = each($result)) {
echo '//c/d: ',$node,"\n";
}
?>