|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2007-10-02 14:26 UTC] rrichards@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sun Oct 26 12:00:01 2025 UTC |
Description: ------------ According to "Namespaces in XML 1.0 (Second Edition)", SS6.2: "A default namespace declaration applies to all unprefixed element names within its scope. Default namespace declarations do not apply directly to attribute names; the interpretation of unprefixed attributes is determined by the element on which they appear." However, SimpleXML appears to treat unprefixed attributes as in the default namespace. This is incorrect. Reproduce code: --------------- <?php $doc1 = <<<LEFIN <foo:bar xmlns:foo="urn:1"> <foo:baz fred="barney"/> </foo:bar> LEFIN; $doc2 = <<<LEFIN <foo:bar xmlns:foo="urn:1"> <foo:baz foo:fred="barney"/> </foo:bar> LEFIN; $kids1 = simplexml_load_string($doc1)->children('urn:1'); $kids2 = simplexml_load_string($doc2)->children('urn:1'); print_r($kids1); print_r($kids2); Expected result: ---------------- SimpleXMLElement Object ( [baz] => SimpleXMLElement Object ( [@attributes] => Array ( [fred] => barney ) ) ) SimpleXMLElement Object ( [baz] => SimpleXMLElement Object ( [@attributes] => Array ( [fred] => barney ) ) ) Actual result: -------------- SimpleXMLElement Object ( [baz] => SimpleXMLElement Object ( ) ) SimpleXMLElement Object ( [baz] => SimpleXMLElement Object ( [@attributes] => Array ( [fred] => barney ) ) )