php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #51641 Adding namespace with addAttribute() adds spurious xmlns:xmlns attribute
Submitted: 2010-04-23 02:06 UTC Modified: 2010-05-18 17:52 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: jpatokal at iki dot fi Assigned:
Status: Wont fix Package: SimpleXML related
PHP Version: 5.2.13 OS: All
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: jpatokal at iki dot fi
New email:
PHP Version: OS:

 

 [2010-04-23 02:06 UTC] jpatokal at iki dot fi
Description:
------------
If you add a new namespace to a document root with addAttribute(), the function incorrectly also tries to add a namespace for the new namespace, resulting in a spurious "xmlns:xmlns" attribute.

Add attribute called "foo:bar"
xmlns:foo="namespace-url" foo:bar="value" <-- correct

Add attribute called "xmlns:bar"
xmlns:xmlns="namespace-url" xmlns:bar="namespace-url" <-- incorrect

A special case is thus needed to ensure that, if the attribute name starts with "xmlns:", a namespace is not added for it:
xmlns:bar="namespace-url" <-- correct

Alternatively, a new function for adding namespaces to a document?


Test script:
---------------
<?php
$xml = new SimpleXMLElement('<office:document-content xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0"/>');
$xml->addAttribute('xmlns:ooow', 'http://openoffice.org/2004/writer', 'http://openoffice.org/2004/writer');
echo $xml->asXML();
?>



Expected result:
----------------
<?xml version="1.0"?>
<office:document-content xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0" xmlns:ooow="http://openoffice.org/2004/writer"/>


Actual result:
--------------
<?xml version="1.0"?>
<office:document-content xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0" xmlns:xmlns="http://openoffice.org/2004/writer" xmlns:ooow="http://openoffice.org/2004/writer"/>


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-05-18 17:52 UTC] mike@php.net
-Status: Open +Status: Wont fix
 [2010-05-18 17:52 UTC] mike@php.net
As its name implies SimpleXML is for simple access to XML, use a more sophisticated interface like DOM.
 
PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Tue Oct 27 13:01:24 2020 UTC