#42829 [NEW]: SimpleXML treats namespaces on attributes incorrectly.

From: Date: Tue, 02 Oct 2007 12:56:06 +0000
Subject: #42829 [NEW]: SimpleXML treats namespaces on attributes incorrectly.
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-118095@lists.php.net to get a copy of this message
From: keith at blacknight dot ie Operating system: Ubuntu 7.04 PHP version: 5.2.4 PHP Bug Type: SimpleXML related Bug description: SimpleXML treats namespaces on attributes incorrectly. 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 ) ) ) -- Edit bug report at http://bugs.php.net/?id=42829&edit=1 -- Try a CVS snapshot (PHP 4.4): http://bugs.php.net/fix.php?id=42829&r=trysnapshot44 Try a CVS snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=42829&r=trysnapshot52 Try a CVS snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=42829&r=trysnapshot60 Fixed in CVS: http://bugs.php.net/fix.php?id=42829&r=fixedcvs Fixed in release: http://bugs.php.net/fix.php?id=42829&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=42829&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=42829&r=needscript Try newer version: http://bugs.php.net/fix.php?id=42829&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=42829&r=support Expected behavior: http://bugs.php.net/fix.php?id=42829&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=42829&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=42829&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=42829&r=globals PHP 3 support discontinued: http://bugs.php.net/fix.php?id=42829&r=php3 Daylight Savings: http://bugs.php.net/fix.php?id=42829&r=dst IIS Stability: http://bugs.php.net/fix.php?id=42829&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=42829&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=42829&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=42829&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=42829&r=mysqlcfg

« previous php.bugs (#118095) next »