ID:               46769
 Comment by:       keith at blacknight dot com
 Reported By:      keith at blacknight dot com
 Status:           Open
 Bug Type:         SimpleXML related
 Operating System: Ubuntu 8.10
 PHP Version:      5.2.7
 New Comment:

Problem also confirmed under FreeBSD 7.0 with PHP 5.2.8.


Previous Comments:
------------------------------------------------------------------------

[2008-12-05 16:53:15] keith at blacknight dot com

Sorry, this line in the sample code:

$child->addAttribute('xsi:schemaLocation', "$ns_foo foo.xsd",
$ns_xsi);

Should be:

$child->addAttribute('schemaLocation', "$ns_foo foo.xsd", $ns_xsi);

------------------------------------------------------------------------

[2008-12-05 16:51:36] keith at blacknight dot com

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 this bug report at http://bugs.php.net/?id=46769&edit=1

Reply via email to