#46185 [Opn->Asn]: importNode changes the namespace of an XML element.

From: Date: Sun, 28 Sep 2008 11:42:59 +0000
Subject: #46185 [Opn->Asn]: importNode changes the namespace of an XML element.
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-129296@lists.php.net to get a copy of this message
 ID:               46185
 Updated by:       rrichards@php.net
 Reported By:      robin2008 at altruists dot org
-Status:           Open
+Status:           Assigned
 Bug Type:         DOM XML related
 Operating System: Ubuntu
 PHP Version:      5.2.6
-Assigned To:      
+Assigned To:      rrichards
 New Comment:

Assign to self


Previous Comments:
------------------------------------------------------------------------

[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)

« previous php.bugs (#129296) next »