|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #43221 SimpleXML adding default namespace in addAttribute
Submitted: 2007-11-09 02:48 UTC Modified: 2007-11-12 19:04 UTC
Avg. Score:1.0 ± 0.0
Reproduced:0 of 1 (0.0%)
From: jevon at jevon dot org Assigned: rrichards (profile)
Status: Closed Package: SimpleXML related
PHP Version: 5.2.4 OS: Windows XP
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.
Block user comment
Status: Assign to:
Bug Type:
From: jevon at jevon dot org
New email:
PHP Version: OS:


 [2007-11-09 02:48 UTC] jevon at jevon dot org
Namespace support in SimpleXML is all screwy. In particular, you cannot add two differently-namespaced attributes to a SimpleXML node; the first one is lost.

Reproduce code:
$xml = new SimpleXMLElement('<root />');
$n = $xml->addChild("node", "value");    // still fails even if we set a NS here
$n->addAttribute("a", "b");    // still fails even if we set a different NS here
$n->addAttribute("c", "d", "");

Expected result:
<root xmlns:a=""><node a="b" a:c="d">value</node></root>

Actual result:
<root><node xmlns="" a="b" c="d">value</node></root>


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2007-11-12 09:55 UTC]
Rob, could you take a look at it plz?
 [2007-11-12 14:41 UTC] hubert dot roksor at gmail dot com
It works just fine if you define your namespace beforehand.

$xml = new SimpleXMLElement('<root xmlns:bar=""/>');
$n = $xml->addChild("node", "value");
$n->addAttribute("a", "b");
$n->addAttribute("c", "d", "");

I don't know, perhaps SimpleXML should raise a E_NOTICE on unknown namespace, but it's really a matter of good coding practice.

Btw, jevon, I don't recommend saying that something is "screwy" when filing bug reports, it doesn't really motivate developpers of said software to look into them ^^;
 [2007-11-12 15:10 UTC]
updated summary.

The bug is that an unprefixed attribute is being allowed to be created with a namespace and a default namespace is being added to the parent element.
 [2007-11-12 19:04 UTC]
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
Thank you for the report, and for helping us make PHP better.

Note that all the examples here will now cause a warning due to trying to create invalid XML.
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Jul 16 10:01:28 2024 UTC