php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #40508 Namespace xpath doesn't work for nested elements
Submitted: 2007-02-16 13:21 UTC Modified: 2007-03-26 20:22 UTC
From: vrana@php.net Assigned: helly (profile)
Status: Not a bug Package: SimpleXML related
PHP Version: 5.2.1 OS: Windows
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
26 + 20 = ?
Subscribe to this entry?

 
 [2007-02-16 13:21 UTC] vrana@php.net
Description:
------------
Registering XPath namespace works only for XPath queries from root element.

Reproduce code:
---------------
$text = '<a xmlns="http://example.org"><b><c>test</c></b></a>';
$xml = simplexml_load_string($text);

// register in root
$xml->registerXPathNamespace("x", "http://example.org");
print_r($xml->b->xpath("x:c"));

// register in nested element
$xml->b->registerXPathNamespace("x", "http://example.org");
print_r($xml->b->xpath("x:c"));


Expected result:
----------------
At least once:

Array
(
    [0] => SimpleXMLElement Object
        (
            [0] => test
        )
)


Actual result:
--------------
Warning: SimpleXMLElement::xpath(): Undefined namespace prefix

Warning: SimpleXMLElement::xpath(): Undefined namespace prefix


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-03-26 20:22 UTC] rrichards@php.net
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

XPath context is per SimpleXMLElement object, so although the register in nested element looks like it would work, that too uses different objects. Thanks for the report though as it did expose a bug with the node being used for the XPath context node though.
 [2010-03-12 12:45 UTC] kkezmg at gmail dot com
So, has this been fixed?
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Jul 12 20:01:30 2024 UTC