#42348 [Opn->Bgs]: xPath beginning with "//" searches whole document
| From: | rrichards@php.net | Date: | Mon, 20 Aug 2007 11:27:04 +0000 |
| Subject: | #42348 [Opn->Bgs]: xPath beginning with "//" searches whole document | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-116355@lists.php.net to get a copy of this message | ||
ID: 42348
Updated by: rrichards@php.net
Reported By: guenther dot stadler at gmx dot net
-Status: Open
+Status: Bogus
Bug Type: SimpleXML related
PHP Version: 5.2.3
New Comment:
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to
report
a bug at http://bugs.php.net/how-to-report.php
Behavior is according to XPath specs: http://www.w3.org/TR/xpath
The SimpleXMLElement used to call the xpath() method is used as the
context node.
Previous Comments:
------------------------------------------------------------------------
[2007-08-20 10:57:38] guenther dot stadler at gmx dot net
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
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=42348&edit=1