|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2008-12-05 16:51 UTC] 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> PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Wed Oct 29 21:00:01 2025 UTC |
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);