php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #34413 DOMXPath->query() ignores context nodes
Submitted: 2005-09-07 22:07 UTC Modified: 2005-09-08 08:48 UTC
From: thisisroot at gmail dot com Assigned:
Status: Not a bug Package: XML related
PHP Version: 5.0.5 OS: Mac OS 10.4.2
Private report: No CVE-ID: None
 [2005-09-07 22:07 UTC] thisisroot at gmail dot com
Description:
------------
DOMXPath->query() seems to totally ignore context nodes. I get 
an empty DOMNodeList when I execute a query with a context 
node.

P.S.: Your bug submission process is a real PITA. Could we 
have just one CAPTCHA, please?


Reproduce code:
---------------
// I just deleted the real code, but here's a sample
// Assume the document and xpath parser have already been
// instantiated.
/*
$doc = 
<kvps>
  <string>
    <key>My Key</key>
    <value>My Value</value>
  <string>
</kvps>
*/
$nodes = $xpath->query( '//string');

foreach ( $nodes as $node) {
  print_r( $node);
  $key = $xpath->query( '//key', $node);
  echo $key->nodeValue . "\n";
  print_r( $key);
}



Expected result:
----------------
I expect $key to be the DOMElement tagged as "key" inside of 
the current "string" element.

Actual result:
--------------
An empty NodeList

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-09-07 23:44 UTC] sniper@php.net
Please try using this CVS snapshot:

  http://snaps.php.net/php5-latest.tar.gz
 
For Windows:
 
  http://snaps.php.net/win32/php5-win32-latest.zip


 [2005-09-08 08:46 UTC] chregu@php.net
your xpath query is not relative. Use

$key = $xpath->query( './/key', $node);

and it works

And please provide a really self runnning example next time, 
we're mostly not in the mood to make your examples running on 
our computers..  
 [2005-09-08 08:48 UTC] chregu@php.net
btw, this:

echo $key->nodeValue . "\n";

is wrong. too. You need to loop through the DomNodeList you 
get from query() with foreach... 
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed Apr 24 23:01:34 2024 UTC