#47848 [Opn->Csd]: importNode doesn't preserve attribute namespaces
| From: | rrichards@php.net | Date: | Thu, 03 Dec 2009 20:21:46 +0000 |
| Subject: | #47848 [Opn->Csd]: importNode doesn't preserve attribute namespaces | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-145381@lists.php.net to get a copy of this message | ||
ID: 47848
Updated by: rrichards@php.net
Reported By: robin2008 at altruists dot org
-Status: Open
+Status: Closed
Bug Type: DOM XML related
Operating System: Ubuntu
PHP Version: 5.2.9
New Comment:
This bug has been fixed in SVN.
Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.
Thank you for the report, and for helping us make PHP better.
Previous Comments:
------------------------------------------------------------------------
[2009-12-03 20:19:38] svn@php.net
Automatic comment from SVN on behalf of rrichards
Revision: http://svn.php.net/viewvc/?view=revision&revision=291669
Log: fix bug #47848 (importNode doesn't preserve attribute namespaces)
add tests
------------------------------------------------------------------------
[2009-03-31 11:29:03] robin2008 at altruists dot org
Description:
------------
I was expecting importNode to preserve attribute namespaces.
It doesn't
Reproduce code:
---------------
<?php
// PHP 5.2.* namespace bug - importNode doesn't preserve attribute
namespaces
$aDOM= new DOMDocument();
$aDOM->appendChild($aDOM->createElementNS('http://friend2friend.net/','f2f:a'));
echo 'DOM to add into is '.$aDOM->saveXML().chr(13);
$fromdom= DOMDocument::loadXML('<data xmlns:ai=" http://altruists.org "
ai:attr="namespaced" />');
echo 'Dom to import from is'.$fromdom->saveXML().chr(13);
$attr= $fromdom->firstChild->attributes->item(0);
$aDOM->documentElement->appendChild($aDOM->importNode($attr));
echo 'Result is '.$aDOM->saveXML();
// The following script gets round this bug
function importAttrNS($targetNode, $attr)
{ // Last modified 2009-01-26 Imports an attribute without losing the
NS, if present
if ($attr->prefix=='')
$targetNode->appendChild($targetNode->ownerDocument->importNode($attr));
else
$targetNode->setAttributeNS($attr->lookupNamespaceURI($attr->prefix),
$attr->prefix.':'.$attr->name, $attr->value);
}
?>
Expected result:
----------------
The imported attribute should keep its namespace.
Actual result:
--------------
The imported attribute becomes unnamespaced.
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=47848&edit=1