php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #47490 insertBefore can lose the namespace of an XML element
Submitted: 2009-02-24 11:42 UTC Modified: 2009-02-24 12:09 UTC
From: robin2008 at altruists dot org Assigned:
Status: Not a bug Package: DOM XML related
PHP Version: 5.2.8 OS: Ubuntu
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: robin2008 at altruists dot org
New email:
PHP Version: OS:

 

 [2009-02-24 11:42 UTC] robin2008 at altruists dot org
Description:
------------
If the namespace of the insertBefore()'d element equals that of its parent, it loses the xmlns attribute, so becomes unnamespaced:( !

Reproduce code:
---------------
<?php
$main= DOMDocument::loadXML('<?xml version="1.0"?><f2f:no-xmlns xmlns:f2f="http://friend2friend.net"/>');
$new= $main->createElement('new');
$new->setAttribute('xmlns', 'http://friend2friend.net');
echo 'Main document= '.$main->saveXML().chr(13);
echo 'New element= '.$main->saveXML($new).chr(13).chr(13);
$main->firstChild->insertBefore($new, $main->firstChild->firstChild);
echo 'insertBefore() changes <new> into an unnamespaced node iff its NS matched the parent node :-( '.$main->saveXML();
?>


Expected result:
----------------
Shouldn't lose the namespace. i.e.

<f2f:no-xmlns xmlns:f2f="http://friend2friend.net"><f2f:new/></f2f:no-xmlns>


Actual result:
--------------
Loses the NS:

<f2f:no-xmlns xmlns:f2f="http://friend2friend.net"><new/></f2f:no-xmlns>


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-02-24 12:09 UTC] chregu@php.net
You have to use createElementNS if you want to create namespaced 
elements.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Wed Jul 09 16:02:26 2025 UTC