From:             
Operating system: CentOS 4
PHP version:      5.3.6
Package:          SimpleXML related
Bug Type:         Bug
Bug description:Can't not inherit parent's namespace (patch)

Description:
------------
There are two issues:

(1) If you addChild(), the new child always inherits the namespace of the
parent.  It is currently impossible to add children with no namespace, to a
parent with a namespace.  Though looking at the code, it is clear that is
intent to distinguish between a NULL namespace value and a blank namespace
value.  I believe the design intent was that NULL means inherit the
parent's namespace, and '' means that no namespace should be used.  The
attached patch does this.



(2) If you specify a namespace of "", addChild() will actually add an
attribute of " xmlns="" ", which is not valid.



Patch is attached.  If the $namespace parameter is "", no namespace is
used, which fixes both issues.

Test script:
---------------
<?php

header('Content-Type: text/plain');



$r = new SimpleXMLElement('<r />');

$c1 = $r->addChild('ns1:child1', NULL, 'urn:myspace1');

$c1->addChild('child2');

echo $r->asXML(), "\n";



$r = new SimpleXMLElement('<r />');

$r->addChild('Thing1', 100, '');

echo $r->asXML(), "\n";



Expected result:
----------------
<?xml version="1.0"?>

<r><ns1:child1 xmlns:ns1="urn:myspace1"><ns1:child2/></ns1:child1></r>



<?xml version="1.0"?>

<r><Thing1>100</Thing1></r>

Actual result:
--------------
<?xml version="1.0"?>

<r><ns1:child1 xmlns:ns1="urn:myspace1"><ns1:child2/></ns1:child1></r>



<?xml version="1.0"?>

<r><Thing1 xmlns="">100</Thing1></r>

-- 
Edit bug report at http://bugs.php.net/bug.php?id=54354&edit=1
-- 
Try a snapshot (PHP 5.2):            
http://bugs.php.net/fix.php?id=54354&r=trysnapshot52
Try a snapshot (PHP 5.3):            
http://bugs.php.net/fix.php?id=54354&r=trysnapshot53
Try a snapshot (trunk):              
http://bugs.php.net/fix.php?id=54354&r=trysnapshottrunk
Fixed in SVN:                        
http://bugs.php.net/fix.php?id=54354&r=fixed
Fixed in SVN and need be documented: 
http://bugs.php.net/fix.php?id=54354&r=needdocs
Fixed in release:                    
http://bugs.php.net/fix.php?id=54354&r=alreadyfixed
Need backtrace:                      
http://bugs.php.net/fix.php?id=54354&r=needtrace
Need Reproduce Script:               
http://bugs.php.net/fix.php?id=54354&r=needscript
Try newer version:                   
http://bugs.php.net/fix.php?id=54354&r=oldversion
Not developer issue:                 
http://bugs.php.net/fix.php?id=54354&r=support
Expected behavior:                   
http://bugs.php.net/fix.php?id=54354&r=notwrong
Not enough info:                     
http://bugs.php.net/fix.php?id=54354&r=notenoughinfo
Submitted twice:                     
http://bugs.php.net/fix.php?id=54354&r=submittedtwice
register_globals:                    
http://bugs.php.net/fix.php?id=54354&r=globals
PHP 4 support discontinued:          http://bugs.php.net/fix.php?id=54354&r=php4
Daylight Savings:                    http://bugs.php.net/fix.php?id=54354&r=dst
IIS Stability:                       
http://bugs.php.net/fix.php?id=54354&r=isapi
Install GNU Sed:                     
http://bugs.php.net/fix.php?id=54354&r=gnused
Floating point limitations:          
http://bugs.php.net/fix.php?id=54354&r=float
No Zend Extensions:                  
http://bugs.php.net/fix.php?id=54354&r=nozend
MySQL Configuration Error:           
http://bugs.php.net/fix.php?id=54354&r=mysqlcfg

Reply via email to