From:             markus dot pfefferle at web dot de
Operating system: Windows 2000
PHP version:      4.3.2
PHP Bug Type:     DOM XML related
Bug description:  XPath only supporting absolute location paths?

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 bug report at http://bugs.php.net/?id=24194&edit=1
-- 
Try a CVS snapshot:         http://bugs.php.net/fix.php?id=24194&r=trysnapshot
Fixed in CVS:               http://bugs.php.net/fix.php?id=24194&r=fixedcvs
Fixed in release:           http://bugs.php.net/fix.php?id=24194&r=alreadyfixed
Need backtrace:             http://bugs.php.net/fix.php?id=24194&r=needtrace
Try newer version:          http://bugs.php.net/fix.php?id=24194&r=oldversion
Not developer issue:        http://bugs.php.net/fix.php?id=24194&r=support
Expected behavior:          http://bugs.php.net/fix.php?id=24194&r=notwrong
Not enough info:            http://bugs.php.net/fix.php?id=24194&r=notenoughinfo
Submitted twice:            http://bugs.php.net/fix.php?id=24194&r=submittedtwice
register_globals:           http://bugs.php.net/fix.php?id=24194&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=24194&r=php3
Daylight Savings:           http://bugs.php.net/fix.php?id=24194&r=dst
IIS Stability:              http://bugs.php.net/fix.php?id=24194&r=isapi
Install GNU Sed:            http://bugs.php.net/fix.php?id=24194&r=gnused

Reply via email to