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:
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 read the docs for xpath_eval: "The optional contextnode can be specified for doing relative XPath queries." Previous Comments: ------------------------------------------------------------------------ [2003-07-06 08:30:58] markus dot pfefferle at web dot de I opened a trouble ticket on the GNOME bug page with this problem, as you claim this to be a libxml-related bug, and after some weeks, this was their reply: +------- Additional Comments From daniel at veillard dot com 2003-07-05 16:12 ------- +Seems that PHP doesn't initialize the "context node" of the +XPath evaluation context. That cannot be solved by libxml2, +this really need to be done by PHP interface code (or an user +accessible routine). The evaluation context is described in the +XPath spec: + http://www.w3.org/TR/xpath#section-Introduction + +Daniel So who's right now? ------------------------------------------------------------------------ [2003-06-15 16:37:25] [EMAIL PROTECTED] See bug #24168 ------------------------------------------------------------------------ [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