Bug #53393 [NEW]: XPath path issue with namespaced elements created with DOMDocument
From:
Operating system: CENTOS 5.5/Fedora 14
PHP version: 5.3.3
Package: DOM XML related
Bug Type: Bug
Bug description:XPath path issue with namespaced elements created with DOMDocument
Description:
------------
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="http://www.w3.org/2005/Atom"
xmlns:other="http://other.w3.org/other"><id>uYG7-sPwjFg</id><published>2009-05-17T18:29:31.000Z</published></entry>
EOT;
$doc = new DOMDocument;
$doc->loadXML($xml);
$xpath = new DOMXPath($doc);
$xpath->registerNamespace('atom', "http://www.w3.org/2005/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');
$doc->appendChild($entry);
$entry->setAttribute('xmlns', "http://www.w3.org/2005/Atom");
$entry->setAttribute('xmlns:other', "http://other.w3.org/other");
$id = $entry->appendChild($doc->createElement('id'));;
$id->appendChild($doc->createTextNode("uYG7-sPwjFg"));
$published = $entry->appendChild($doc->createElement('published'));
$published->appendChild($doc->createTextNode("2009-05-17T18:29:31.000Z"));
$xpath = new DOMXPath($doc);
$xpath->registerNamespace('atom', "http://www.w3.org/2005/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
--
Edit bug report at http://bugs.php.net/bug.php?id=53393&edit=1
--
Try a snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=53393&r=trysnapshot52
Try a snapshot (PHP 5.3): http://bugs.php.net/fix.php?id=53393&r=trysnapshot53
Try a snapshot (trunk): http://bugs.php.net/fix.php?id=53393&r=trysnapshottrunk
Fixed in SVN: http://bugs.php.net/fix.php?id=53393&r=fixed
Fixed in SVN and need be documented: http://bugs.php.net/fix.php?id=53393&r=needdocs
Fixed in release: http://bugs.php.net/fix.php?id=53393&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=53393&r=needtrace
Need Reproduce Script: http://bugs.php.net/fix.php?id=53393&r=needscript
Try newer version: http://bugs.php.net/fix.php?id=53393&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=53393&r=support
Expected behavior: http://bugs.php.net/fix.php?id=53393&r=notwrong
Not enough info: http://bugs.php.net/fix.php?id=53393&r=notenoughinfo
Submitted twice: http://bugs.php.net/fix.php?id=53393&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=53393&r=globals
PHP 4 support discontinued: http://bugs.php.net/fix.php?id=53393&r=php4
Daylight Savings: http://bugs.php.net/fix.php?id=53393&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=53393&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=53393&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=53393&r=float
No Zend Extensions: http://bugs.php.net/fix.php?id=53393&r=nozend
MySQL Configuration Error: http://bugs.php.net/fix.php?id=53393&r=mysqlcfg
Thread (2 messages)
- paul dot visco at roswellpark dot org