#41663 [NEW]: Xpath evaluation in SimpleXMLElement
| From: | kenashkov at gmail dot com | Date: | Tue, 12 Jun 2007 08:10:56 +0000 |
| Subject: | #41663 [NEW]: Xpath evaluation in SimpleXMLElement | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-113674@lists.php.net to get a copy of this message | ||
From: kenashkov at gmail dot com
Operating system: Fedora Core 4
PHP version: 5.2.3
PHP Bug Type: SimpleXML related
Bug description: Xpath evaluation in SimpleXMLElement
Description:
------------
The evaluation of the Xpath expressions is not relative to the node
against which they are called ([2]). Worse - even after cloning a node from
the structure and evaluating the xpath, the xpath expression seems to be
evaluated against the original structure, not against the new one (which is
a copy of a part of the original) ([3]).
This was discussed in the dev-list here:
http://marc.info/?l=php-dev&m=118001203709813&w=2
If this is not a bug, but expected result, I think a note addressing this
behaviour must be added in the docs.
Reproduce code:
---------------
$str =
'<rootnode><level1_node1><level2_node1></level2_node1></level1_node1><level1_node2></level1_node2></rootnode>';
$x = new SimpleXMLElement($str);
//[1]
$r1 = $x->xpath('/*');
print $r1[0]->getName().' ';
//[2]
$r2 = $x->level1_node1[0]->xpath('/*');
print $r2[0]->getName().' ';
//[3]
$z = clone $x->level1_node1[0];
$r3 = $z->xpath('/*');
print $r3[0]->getName().' ';
Expected result:
----------------
rootnode level1_node1 level1_node1
Actual result:
--------------
rootnode rootnode rootnode
--
Edit bug report at http://bugs.php.net/?id=41663&edit=1
--
Try a CVS snapshot (PHP 4.4): http://bugs.php.net/fix.php?id=41663&r=trysnapshot44
Try a CVS snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=41663&r=trysnapshot52
Try a CVS snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=41663&r=trysnapshot60
Fixed in CVS: http://bugs.php.net/fix.php?id=41663&r=fixedcvs
Fixed in release: http://bugs.php.net/fix.php?id=41663&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=41663&r=needtrace
Need Reproduce Script: http://bugs.php.net/fix.php?id=41663&r=needscript
Try newer version: http://bugs.php.net/fix.php?id=41663&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=41663&r=support
Expected behavior: http://bugs.php.net/fix.php?id=41663&r=notwrong
Not enough info: http://bugs.php.net/fix.php?id=41663&r=notenoughinfo
Submitted twice: http://bugs.php.net/fix.php?id=41663&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=41663&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=41663&r=php3
Daylight Savings: http://bugs.php.net/fix.php?id=41663&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=41663&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=41663&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=41663&r=float
No Zend Extensions: http://bugs.php.net/fix.php?id=41663&r=nozend
MySQL Configuration Error: http://bugs.php.net/fix.php?id=41663&r=mysqlcfg