|  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
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
Have you experienced this issue?
Rate the importance of this bug to you:

 [2010-04-23 02:06 UTC] jpatokal at iki dot fi
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:
$xml = new SimpleXMLElement('<office:document-content xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0"/>');
$xml->addAttribute('xmlns:ooow', '', '');
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=""/>

Actual result:
<?xml version="1.0"?>
<office:document-content xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0" xmlns:xmlns="" xmlns:ooow=""/>


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2010-05-18 17:52 UTC]
-Status: Open +Status: Wont fix
 [2010-05-18 17:52 UTC]
As its name implies SimpleXML is for simple access to XML, use a more sophisticated interface like DOM.
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Jun 15 08:01:28 2024 UTC