|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #55294 DOMDocument::importNode shifts namespaces when "default" namespace exists
Submitted: 2011-07-27 12:35 UTC Modified: 2013-12-02 19:40 UTC
Avg. Score:4.8 ± 0.4
Reproduced:4 of 4 (100.0%)
Same Version:1 (25.0%)
Same OS:2 (50.0%)
From: hilse at web dot de Assigned:
Status: Not a bug Package: DOM XML related
PHP Version: trunk-SVN-2011-07-27 (snap) OS: Linux
Private report: No CVE-ID: None
 [2011-07-27 12:35 UTC] hilse at web dot de
When importing nodes and their children via DOMDocument::importNode, the method 
will introduce the "default" namespace prefix. Herein lies a bug that will trigger 
if the namespace prefix "default" is already assigned (even if not applied to any 
element) within the children of the imported node.

Test script:
<A xmlns="">
			xmlns:default="" />

$bDOM=new DOMDocument();
$node = $bDOM->importNode($aDOM->getElementsByTagNameNS('','B')->item(0), true);

echo $bDOM->saveXML()."\n";

Expected result:
<?xml version="1.0"?>
<B xmlns="" xmlns:default="">
		<default:C />

or even better:

<?xml version="1.0"?>
<B xmlns="">
		<C xmlns=""/>

Actual result:
<?xml version="1.0"?>
<B xmlns="" xmlns:default="">
	<default:C xmlns="" 

(see how C is put into the ".../Z" namespace now instead of ".../C", since 
namespace prefix declarations are valid for the element in which they are 


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2013-12-02 19:40 UTC]
-Status: Open +Status: Not a bug
 [2013-12-02 19:40 UTC]
If, then an upstream bug of libxml2.

xmlNewReconciliedNS() uses "default" as prefix if not already found in the doc.

So either don't use default, or looking at libxml2 sources, default followed by a number in the range 0-1000, or file a bug at

And on a side note: it happens on append not import.
PHP Copyright © 2001-2022 The PHP Group
All rights reserved.
Last updated: Sun Sep 25 21:03:42 2022 UTC