php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #42348 xPath beginning with "//" searches whole document
Submitted: 2007-08-20 10:57 UTC Modified: 2007-08-20 11:27 UTC
Votes:1
Avg. Score:3.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: guenther dot stadler at gmx dot net Assigned:
Status: Not a bug Package: SimpleXML related
PHP Version: 5.2.3 OS:
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: guenther dot stadler at gmx dot net
New email:
PHP Version: OS:

 

 [2007-08-20 10:57 UTC] 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 

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-08-20 11:27 UTC] rrichards@php.net
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.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Dec 26 10:01:29 2024 UTC