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
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
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

Add a Patch

Pull Requests

Add a Pull Request

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-2024 The PHP Group
All rights reserved.
Last updated: Wed Jul 03 12:01:30 2024 UTC