Bug #53393 [Opn->Bgs]: XPath path issue with namespaced elements created with DOMDocument

From: Date: Tue, 11 Jan 2011 18:02:15 +0000
Subject: Bug #53393 [Opn->Bgs]: XPath path issue with namespaced elements created with DOMDocument
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-157820@lists.php.net to get a copy of this message
Edit report at http://bugs.php.net/bug.php?id=53393&edit=1

 ID:                 53393
 Updated by:         rrichards@php.net
 Reported by:        paul dot visco at roswellpark dot org
 Summary:            XPath path issue with namespaced elements created
                     with DOMDocument
-Status:             Open
+Status:             Bogus
 Type:               Bug
 Package:            DOM XML related
 Operating System:   CENTOS 5.5/Fedora 14
 PHP Version:        5.3.3
 Block user comment: N
 Private report:     N

 New Comment:

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

must use dom level 2 namespace aware methods


Previous Comments:
------------------------------------------------------------------------
[2010-11-24 04:01:43] paul dot visco at roswellpark dot org

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 this bug report at http://bugs.php.net/bug.php?id=53393&edit=1


Thread (2 messages)

« previous php.bugs (#157820) next »