note 51995 deleted from function.simplexml-element-xpath by victor
| From: | victor@php.net | Date: | Mon, 18 Apr 2005 14:14:17 +0000 |
| Subject: | note 51995 deleted from function.simplexml-element-xpath by victor | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-88162@lists.php.net to get a copy of this message | ||
Note Submitter: jcnorris at me3 dot com
Reason: useless
----
This is non-intuitive to me, but here it is:
The following code:
<?php
$xmlstr =
"<a>
<b>
<c>apple</c>
</b>
<b>
<c>peach</c>
</b>
</a>";
$xmlobj = simplexml_load_string($xmlstr);
foreach ($xmlobj->b as $subxmlobj) {
echo "\n----------------------:\n";
$xstuff = $subxmlobj->xpath('//c');
var_dump ($subxmlobj, $xstuff);
}
?>
Will return the following result:
----------------------:
object(SimpleXMLElement)#4 (1) {
["c"]=>
string(5) "apple"
}
array(2) {
[0]=>
object(SimpleXMLElement)#5 (1) {
[0]=>
string(5) "apple"
}
[1]=>
object(SimpleXMLElement)#6 (1) {
[0]=>
string(5) "peach"
}
}
----------------------:
object(SimpleXMLElement)#7 (1) {
["c"]=>
string(5) "peach"
}
array(2) {
[0]=>
object(SimpleXMLElement)#4 (1) {
[0]=>
string(5) "apple"
}
[1]=>
object(SimpleXMLElement)#8 (1) {
[0]=>
string(5) "peach"
}
}
The xpath query retrieves elements "outside" the object.