|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #47848 importNode doesn't preserve attribute namespaces
Submitted: 2009-03-31 11:29 UTC Modified: 2009-12-03 20:21 UTC
Avg. Score:3.0 ± 0.0
Reproduced:2 of 2 (100.0%)
Same Version:1 (50.0%)
Same OS:2 (100.0%)
From: robin2008 at altruists dot org Assigned:
Status: Closed Package: DOM XML related
PHP Version: 5.2.9 OS: Ubuntu
Private report: No CVE-ID: None
 [2009-03-31 11:29 UTC] robin2008 at altruists dot org
I was expecting importNode to preserve attribute namespaces.
It doesn't

Reproduce code:
// PHP 5.2.* namespace bug - importNode doesn't preserve attribute namespaces

$aDOM= new DOMDocument();
echo 'DOM to add into is '.$aDOM->saveXML().chr(13);

$fromdom= DOMDocument::loadXML('<data xmlns:ai=" " ai:attr="namespaced" />');
echo 'Dom to import from is'.$fromdom->saveXML().chr(13);

$attr= $fromdom->firstChild->attributes->item(0);

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.


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2009-12-03 20:19 UTC]
Automatic comment from SVN on behalf of rrichards
Log: fix bug #47848 (importNode doesn't preserve attribute namespaces)
add tests
 [2009-12-03 20:21 UTC]
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
Thank you for the report, and for helping us make PHP better.

PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Mon Jun 17 07:01:30 2024 UTC