#41955 [NEW]: addChild() with no namespace defined ignores the default namespace
| From: | hubert dot roksor at gmail dot com | Date: | Tue, 10 Jul 2007 20:53:48 +0000 |
| Subject: | #41955 [NEW]: addChild() with no namespace defined ignores the default namespace | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-114858@lists.php.net to get a copy of this message | ||
From: hubert dot roksor at gmail dot com
Operating system:
PHP version: 5CVS-2007-07-10 (snap)
PHP Bug Type: SimpleXML related
Bug description: addChild() with no namespace defined ignores the default namespace
Description:
------------
When adding a non-namespaced element to namespaced one, the new element is
created under its parent's namespace instead of the scope's default
namespace.
In the reproduce code below we create a tree whose root element carries an
empty default namespace declaration, with one "child" element under a
custom namespace. We use addChild() to add a grandchild with no namespace
defined. As per my understanding of XML Namespaces specifications, that
element should be created under the default namespace and since the default
namespace is empty the element should not use any namespace at all.
A few notes:
- moving the default namespace declaration to the child node does not
change the outcome
- using a non-empty default namespace does not change the outcome
- specifying an empty namespace using addChild()'s third parameter gives
the expected result
Tested on:
PHP 5.2.4-dev (cli) (built: Jul 10 2007 12:04:20)
libXML Version => 2.6.26
SimpleXML Revision => $Revision: 1.151.2.22.2.33 $
Thanks for reading, and thanks for fixing my previous bugs so quickly ;)
Reproduce code:
---------------
<?php
$xml = simplexml_load_string('<?xml version="1.0" encoding="utf-8"?>
<root xmlns:myns="http://myns" xmlns="">
<myns:child />
</root>');
$children = $xml->children('http://myns');
$children[0]->addChild('grandchild', 'hello');
echo $xml->asXML();
?>
Expected result:
----------------
<?xml version="1.0" encoding="utf-8"?>
<root xmlns:myns="http://myns" xmlns="">
<myns:child><grandchild>hello</grandchild></myns:child>
</root>
Actual result:
--------------
<?xml version="1.0" encoding="utf-8"?>
<root xmlns:myns="http://myns" xmlns="">
<myns:child><myns:grandchild>hello</myns:grandchild></myns:child>
</root>
--
Edit bug report at http://bugs.php.net/?id=41955&edit=1
--
Try a CVS snapshot (PHP 4.4): http://bugs.php.net/fix.php?id=41955&r=trysnapshot44
Try a CVS snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=41955&r=trysnapshot52
Try a CVS snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=41955&r=trysnapshot60
Fixed in CVS: http://bugs.php.net/fix.php?id=41955&r=fixedcvs
Fixed in release: http://bugs.php.net/fix.php?id=41955&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=41955&r=needtrace
Need Reproduce Script: http://bugs.php.net/fix.php?id=41955&r=needscript
Try newer version: http://bugs.php.net/fix.php?id=41955&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=41955&r=support
Expected behavior: http://bugs.php.net/fix.php?id=41955&r=notwrong
Not enough info: http://bugs.php.net/fix.php?id=41955&r=notenoughinfo
Submitted twice: http://bugs.php.net/fix.php?id=41955&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=41955&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=41955&r=php3
Daylight Savings: http://bugs.php.net/fix.php?id=41955&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=41955&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=41955&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=41955&r=float
No Zend Extensions: http://bugs.php.net/fix.php?id=41955&r=nozend
MySQL Configuration Error: http://bugs.php.net/fix.php?id=41955&r=mysqlcfg