php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #42829 SimpleXML treats namespaces on attributes incorrectly.
Submitted: 2007-10-02 12:56 UTC Modified: 2007-10-02 14:26 UTC
From: keith at blacknight dot ie Assigned:
Status: Not a bug Package: SimpleXML related
PHP Version: 5.2.4 OS: Ubuntu 7.04
Private report: No CVE-ID: None
 [2007-10-02 12:56 UTC] keith at blacknight dot ie
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
                )

        )

)


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-10-02 14:26 UTC] rrichards@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

Unprefixed attributes have no namespace so its up to the application to determine what the attribute means in context of the element.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Dec 26 13:01:30 2024 UTC