importNode changes the namespace of an XML element.
| Bug #46185 | importNode changes the namespace of an XML element. | ||||
|---|---|---|---|---|---|
| Submitted: | 2008-09-26 16:29 UTC | Modified: | 2008-09-29 16:53 UTC | ||
| From: | robin2008 at altruists dot org | Assigned: | rrichards (profile) | ||
| Status: | Closed | Package: | DOM XML related | ||
| PHP Version: | 5.2.6 | OS: | Ubuntu | ||
| Private report: | No | CVE-ID: | None | ||
[2008-09-26 16:29 UTC] 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>
Patches
Pull Requests
History
AllCommentsChangesGit/SVN commits
[2008-09-29 16:53 UTC] rrichards@php.net