#46185 [Asn->Csd]: importNode changes the namespace of an XML element.
ID: 46185
Updated by: rrichards@php.net
Reported By: robin2008 at altruists dot org
-Status: Assigned
+Status: Closed
Bug Type: DOM XML related
Operating System: Ubuntu
PHP Version: 5.2.6
Assigned To: rrichards
New Comment:
This bug has been fixed in CVS.
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.
Fixed in 5_3
Previous Comments:
------------------------------------------------------------------------
[2008-09-28 11:42:58] rrichards@php.net
Assign to self
------------------------------------------------------------------------
[2008-09-26 16:29:44] robin2008 at altruists dot org
Description:
------------
The problem occurs when an element has an unused namespace node
xmlns:default which is hanging around, unused.
When imorting a node under certain conditions, the parent node sets an
xmlns:default which is intended to apply to the imported Node, but
doesn't because xmlns:default applies instead.
The net effect is that the imported node changes namespace.
Reproduce code:
---------------
<?php
$aDOM = new DOMDocument;
$aDOM->loadXML('<?xml version="1.0"?><f2f:a
xmlns:f2f="http://friend2friend.net"/>');
$a= $aDOM->firstChild;
echo 'DOM is add into is '.$aDOM->saveXML().chr(13);
$ok = new DOMDocument;
$ok->loadXML('<f2f:ok xmlns:f2f="http://friend2friend.net"
xmlns="REAL"><watch-me xmlns:default="BOGUS"/></f2f:ok>');
$imported= $aDOM->importNode($ok->firstChild, true);
echo 'Node to import is '.$aDOM->saveXML($imported).chr(13).chr(13);
$a->appendChild($imported);
echo 'Result is '.$aDOM->saveXML();
?>
Expected result:
----------------
DOM is add into is <?xml version="1.0"?>
<f2f:a xmlns:f2f="http://friend2friend.net"/>
Node to import is <f2f:ok xmlns:f2f="http://friend2friend.net"
xmlns="REAL"><watch-me xmlns:default="BOGUS"/></f2f:ok>
Result is <?xml version="1.0"?>
<f2f:a xmlns:f2f="http://friend2friend.net"><f2f:ok
xmlns:default1="REAL"><default1:watch-me
xmlns:default="BOGUS"/></f2f:ok></f2f:a>
Actual result:
--------------
DOM is add into is <?xml version="1.0"?>
<f2f:a xmlns:f2f="http://friend2friend.net"/>
Node to import is <f2f:ok xmlns:f2f="http://friend2friend.net"
xmlns="REAL"><watch-me xmlns:default="BOGUS"/></f2f:ok>
Result is <?xml version="1.0"?>
<f2f:a xmlns:f2f="http://friend2friend.net"><f2f:ok
xmlns:default="REAL"><default:watch-me
xmlns:default="BOGUS"/></f2f:ok></f2f:a>
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=46185&edit=1
Thread (3 messages)