|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #53393 XPath path issue with namespaced elements created with DOMDocument
Submitted: 2010-11-24 04:01 UTC Modified: 2011-01-11 19:02 UTC
From: paul dot visco at roswellpark dot org Assigned:
Status: Not a bug Package: DOM XML related
PHP Version: 5.3.3 OS: CENTOS 5.5/Fedora 14
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: paul dot visco at roswellpark dot org
New email:
PHP Version: OS:


 [2010-11-24 04:01 UTC] paul dot visco at roswellpark dot org
When creating a namespaced DOMDocument programmatically (appendChild, etc), I cannot get DOMXPath to return the same results on the same underlying XML document as I can when use DOMDocument->loadXML() to populate the documents XML.

I compiled and tested the latest PHP 5.3.4RC2-dev (cli) (built: Nov 23 2010 21:51:46) using --with-dom and --with-xml and used the latest stable libxml2-devel.x86_64 2.7.7-2.fc14 from fedora 14 and the problem still persists.

Sorry its like 25 lines of code with comments, I don't have somewhere else to put them.

Test script:
//Constructing the DOMDocument from XML string allows DOMXPath to work
$xml = <<<EOT
<?xml version="1.0" encoding="UTF-8"?>
<entry xmlns="" xmlns:other=""><id>uYG7-sPwjFg</id><published>2009-05-17T18:29:31.000Z</published></entry>
$doc = new DOMDocument;
$xpath = new DOMXPath($doc);
$xpath->registerNamespace('atom', "");
$entries = $xpath->evaluate('//atom:entry/atom:published/text()');
///prints 2009-05-17T18:29:31.000Z as expected
print $entries->item(0)->nodeValue ;

//Constructing the same exact document programmatically causes DOMXPath to not work
$doc = new DOMDocument("1.0", "UTF-8");
$entry = $doc->createElement('entry');
$entry->setAttribute('xmlns', "");
$entry->setAttribute('xmlns:other', "");
$id = $entry->appendChild($doc->createElement('id'));;
$published = $entry->appendChild($doc->createElement('published'));

$xpath = new DOMXPath($doc);
$xpath->registerNamespace('atom', "");
$entries = $xpath->evaluate('//atom:entry/atom:published/text()');
//throws error as node is not found
print $entries->item(0)->nodeValue;

Expected result:
I would expect both of the above examples to print 2009-05-17T18:29:31.000Z

Actual result:
Example one prints 2009-05-17T18:29:31.000Z and example 2 fails because the node is not found by Xpath


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2011-01-11 19:02 UTC]
-Status: Open +Status: Bogus
 [2011-01-11 19:02 UTC]
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at and the instructions on how to report
a bug at

must use dom level 2 namespace aware methods
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Tue Jul 27 10:01:23 2021 UTC