note 51995 added to function.simplexml-element-xpath
| From: | jcnorris at me3 dot com | Date: | Mon, 18 Apr 2005 13:28:19 +0000 |
| Subject: | note 51995 added to function.simplexml-element-xpath | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-88154@lists.php.net to get a copy of this message | ||
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.
----
Manual Page -- http://www.php.net/manual/en/function.simplexml-element-xpath.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+51995
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+51995&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+51995&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+51995&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+51995&report=yes&reason=useless
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+51995&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+51995&report=yes
Search -- http://master.php.net/manage/user-notes.php