|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2007-08-20 11:27 UTC] rrichards@php.net
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Fri Oct 24 14:00:01 2025 UTC |
Description: ------------ When using // at the beginning of an xpath-query, not only the children of the current SimpleXMLElement are searched (as stated in the manual), but the whole XML document instead. (So, actually, it might only be a documentation issue...) If this is expected behaviour, how is one supposed to search all <bar> elements, no whether where they are - but only under the current item (whatever it might be)? Reproduce code: --------------- <?php $xmlstr = <<<XML <?xml version='1.0' standalone='yes'?> <root> <foo id="foo_1"> <node> <bar>1</bar> <bar>2</bar> </node> </foo> <foo id="foo_2"> <node> <bar>3</bar> <bar>4</bar> </node> </foo> </root> XML; $xml = new SimpleXMLElement($xmlstr); $foo_list = $xml->xpath('//foo'); $foo = $foo_list[0]; // now we have the node with id="foo_1" $bar_list = $foo->xpath('//bar'); foreach($bar_list as $this_bar) echo "$this_bar "; ?> Expected result: ---------------- 1 2 Actual result: -------------- 1 2 3 4