php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
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

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2008-09-28 11:42 UTC] rrichards@php.net
Assign to self
 [2008-09-29 16:53 UTC] rrichards@php.net
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
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Mar 19 07:01:29 2024 UTC