ID: 24194 Updated by: [EMAIL PROTECTED] Reported By: markus dot pfefferle at web dot de -Status: Open +Status: Bogus Bug Type: DOM XML related Operating System: Windows 2000 PHP Version: 4.3.2 New Comment:
See bug #24168 Previous Comments: ------------------------------------------------------------------------ [2003-06-15 11:16:45] markus dot pfefferle at web dot de Description: ------------ By the definition of XPath from http://www.w3.org/TR/xpath, the xpath expression 'foo' (being an abbreviated syntax of 'child::foo') is a Relative Location Path and would reference to all child nodes of the given context node with a tagname of 'foo'. The expression '/foo' ('/child::foo') is an Absolute Location Path which references the child nodes named 'foo' of the context node's document root node. So the following small code: $s = '<?xml version="1.0" ?>'; $s .= '<foo>'; $s .= '<bar/>'; $s .= '</foo>'; $doc = domxml_open_mem($s); $ctx = xpath_new_context($doc); $n = xpath_eval($ctx, 'foo'); should by strict XPath definition result in the refrencing of the <foo> element just because foo is a child node of the document root node. However, this always results in an empty $n->nodeset. This is the first error. The Absolute Location Path '/foo' however, used in the above xpath_eval(), would deliver the expected node correctly in $n->nodeset[0]. Now if we use this node as a new context node: $ctx = xpath_new_context($n->nodeset[0]); $n = xpath_eval($ctx, 'bar'); Again, by W3C Definition, this should deliver the bar-Element, but instead it will find nothing. Altering the expression to '/bar' however suddenly finds the bar-Node. But this is incorret, since the expression '/bar' would read "the child nodes of the context node's document's root node named 'bar'" - which are non-existent, because the document's root node only child node is 'foo'. So instead the current implementation of XPath seems to treat the preceding slash as mandatory and only referencing to the context node - not the document root. This is not in accordance to XPath! Reproduce code: --------------- $s = '<?xml version="1.0" ?>'; $s .= '<foo>'; $s .= '<bar>'; $s .= 'abc'; $s .= '</bar>'; $s .= '</foo>'; $doc = domxml_open_mem($s); $ctx = xpath_new_context($doc); $a = xpath_eval($ctx, 'foo'); $b = xpath_eval($ctx, '/foo'); $ctx = xpath_new_context($b->nodeset[0]); $c = xpath_eval($ctx, 'bar'); $d = xpath_eval($ctx, '/bar'); echo "a = $a <br> b = $b <br> c = $c <br> d = $d";($ctx, '/foo'); Expected result: ---------------- a = Object b = Object c = Object d = Actual result: -------------- a = b = Object c = d = Object ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=24194&edit=1