From:             keith at blacknight dot com
Operating system: Ubuntu 8.10
PHP version:      5.2.7
PHP Bug Type:     SimpleXML related
Bug description:  addAttributes requires prefix even when namespace is 
previously declared

Description:
------------
Before bug #43221 <http://bugs.php.net/bug.php?id=43221> was fixed,
addAttribute did not requires attribute names to be qnames where the
namespace has previously been declared on a parent element of the element
to which the attribute was being added. Revision 1.246 <http://url.ie/yxb>
broke this by requiring both that attributes with a namespace other than
the default namespace *must* be prefixed regardless of whether the
namespace has been declared with a prefix or not.

SimpleXML->addAttribute() should only require qnames be prefixed if and
only if the namespace provided has not been previously declared.

Reproduce code:
---------------
<?php
$ns_foo = "tag:example.com,2008:foo";
$ns_xsi = "http://www.w3.org/2001/XMLSchema-instance";;

$root_doc = <<<EOT
<?xml version="1.0" encoding="UTF-8"?>
<a xmlns:xsi="$ns_xsi"
   xmlns="tag:example.com,2008"
   xsi:schemaLocation="tag:example.com,2008 root.xsd"
   xmlns:foo="$ns_foo"/>
EOT;

$root = simplexml_load_string($root_doc);
print_r($root->asXml());
$child = $root->addChild('bar', null, $ns_foo);
print_r($root->asXml());
$child->addAttribute('xsi:schemaLocation', "$ns_foo foo.xsd", $ns_xsi);
print_r($root->asXml());


Expected result:
----------------
<?xml version="1.0" encoding="UTF-8"?>
<a xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
xmlns="tag:example.com,2008" xmlns:foo="tag:example.com,2008:foo"
xsi:schemaLocation="tag:example.com,2008 root.xsd"><foo:bar
xsi:schemaLocation="tag:example.com,2008:foo foo.xsd"/></a>

Actual result:
--------------
Warning: SimpleXMLElement::addAttribute(): Attribute requires prefix for
namespace in /home/keith/simplexml-regression.php on line 15
<?xml version="1.0" encoding="UTF-8"?>
<a xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
xmlns="tag:example.com,2008" xmlns:foo="tag:example.com,2008:foo"
xsi:schemaLocation="tag:example.com,2008 root.xsd"><foo:bar/></a>

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

Reply via email to