|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #47530 Importing objects into document fragments creates bogus "default" namespace
Submitted: 2009-02-28 14:48 UTC Modified: 2017-10-24 06:15 UTC
Avg. Score:4.4 ± 0.9
Reproduced:16 of 16 (100.0%)
Same Version:6 (37.5%)
Same OS:5 (31.2%)
From: sgunderson at bigfoot dot com Assigned:
Status: Open Package: DOM XML related
PHP Version: 5.2.9 OS: Debian
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Bug Type:
From: sgunderson at bigfoot dot com
New email:
PHP Version: OS:


 [2009-02-28 14:48 UTC] sgunderson at bigfoot dot com

When I import a DOM node via a document fragment, suddenly a "default" namespace comes out of nowhere (and it's really hard to remove, short of making my own cloneNode() simulation stripping it).

IIRC PHP4 got this right (although it had lots of other issues), and all other languages I've tested in (Perl, Python, Ruby) do as well. Note that the code below doesn't strictly need importNode(), but I cannot really do with cloneNode() in the real code (it's vastly simplified).

Note: On the surface, this appears to be the same bug as #46185, but I tested 5.3 CVS (as of 2009-02-28) and it's still there.

Reproduce code:

$doc = new DOMDocument;
$doc->loadXML('<html xmlns="something" xmlns:ns="whatever"><element ns:foo="bar" /></html>');
$root = $doc->documentElement;
$elem = $root->firstChild;
$frag = $doc->createDocumentFragment();
print $doc->saveXML();


Expected result:
<?xml version="1.0"?>
<html xmlns="something" xmlns:ns="whatever"><element ns:foo="bar"/></html>

Actual result:
<?xml version="1.0"?>
<html xmlns="something" xmlns:ns="whatever"><default:element xmlns:default="something" xmlns:ns="whatever" ns:foo="bar"/></html>


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2010-06-20 21:31 UTC]
-Status: Open +Status: Assigned -Assigned To: +Assigned To: rrichards
 [2011-01-12 08:34 UTC] mplomer at gmx dot de
This does not only affect DocumentFragments. I had this problem with a simple importNode() when having multiple default namespaces. Here is a simplified XML sample:

Reproduce code:

$xml = '<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="">
    <div xmlns="">

$dom = new DOMDocument();

$dom2 = new DOMDocument();
$importedNode = $dom2->importNode($dom->documentElement, true);

echo $dom2->saveXML();


Actual result:
<?xml version="1.0"?>
<feed xmlns="" xmlns:default="">
    <default:div xmlns="">
 [2013-12-03 07:45 UTC]
-Status: Assigned +Status: Analyzed
 [2013-12-03 07:45 UTC]
libxml2 issue.

See also bug #55294
 [2017-10-24 05:14 UTC]
-Status: Analyzed +Status: Assigned
 [2017-10-24 06:15 UTC]
-Status: Assigned +Status: Open -Assigned To: rrichards +Assigned To:
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Sat Nov 27 09:03:13 2021 UTC