Edit report at http://bugs.php.net/bug.php?id=47530&edit=1
ID: 47530
Comment by: mplomer at gmx dot de
Reported by: sgunderson at bigfoot dot com
Summary: Importing objects into document fragments creates
bogus "default" namespace
Status: Assigned
Type: Bug
Package: DOM XML related
Operating System: Debian
PHP Version: 5.2.9
Assigned To: rrichards
Block user comment: N
Private report: N
New Comment:
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:
---------------
<?php
$xml = '<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
<div xmlns="http://www.w3.org/1999/xhtml">
<p>Test-Text</p>
</div>
</feed>';
$dom = new DOMDocument();
$dom->loadXML($xml);
$dom2 = new DOMDocument();
$importedNode = $dom2->importNode($dom->documentElement, true);
$dom2->appendChild($importedNode);
echo $dom2->saveXML();
?>
Actual result:
--------------
<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom"
xmlns:default="http://www.w3.org/1999/xhtml">
<default:div xmlns="http://www.w3.org/1999/xhtml">
<default:p>Test-Text</default:p>
</default:div>
</feed>
Previous Comments:
------------------------------------------------------------------------
[2009-02-28 14:48:20] sgunderson at bigfoot dot com
Description:
------------
Hi,
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:
---------------
<?php
$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();
$frag->appendChild($doc->importNode($elem));
$root->appendChild($frag);
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>
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/bug.php?id=47530&edit=1