php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #75929 Attributes not shown in print_r output loading with LIBXML_NOCDATA
Submitted: 2018-02-07 14:51 UTC Modified: 2021-07-19 13:11 UTC
From: victor-vansloun at hotmail dot com Assigned: cmb (profile)
Status: Duplicate Package: SimpleXML related
PHP Version: 7.1.14 OS: Linux, Apache, Plesklin
Private report: No CVE-ID: None
 [2018-02-07 14:51 UTC] victor-vansloun at hotmail dot com
Description:
------------
The simplexml_load_string function loads attributes correctly when no options are specified. But when the LIBXML_NOCDATA option used, attributes are not specified.

Test script:
---------------
$xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>
<root>
    <item>
        <foo id=\"1\"><![CDATA[123]]></foo>
        <bar><![CDATA[abc]]></bar>
    </item>
    <item>
        <foo id=\"1\">123</foo>
        <bar>abc</bar>
    </item>
</root>";

print_r(simplexml_load_string($xml, null, LIBXML_NOCDATA));

Expected result:
----------------
SimpleXMLElement Object
(
    [item] => Array
        (
            [0] => SimpleXMLElement Object
                (
                    [@attributes] => Array
                        (
                            [id] => 1
                        )
                    [foo] => 123
                    [bar] => abc
                )

            [1] => SimpleXMLElement Object
                (
                    [foo] => 123
                    [bar] => abc
                )

        )

)

Actual result:
--------------
SimpleXMLElement Object
(
    [item] => Array
        (
            [0] => SimpleXMLElement Object
                (
                    [foo] => 123
                    [bar] => abc
                )

            [1] => SimpleXMLElement Object
                (
                    [foo] => 123
                    [bar] => abc
                )

        )

)

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2018-02-07 15:24 UTC] requinix@php.net
-Summary: No attributes with LIBXML_NOCDATA +Summary: Attributes not shown in print_r output loading with LIBXML_NOCDATA -Status: Open +Status: Verified
 [2018-02-07 15:24 UTC] requinix@php.net
Trying to access the attributes easily proves they are there. Just not visible in the print_r output.
https://3v4l.org/tJnmm
 [2021-07-19 13:11 UTC] cmb@php.net
-Status: Verified +Status: Duplicate -Assigned To: +Assigned To: cmb
 [2021-07-19 13:11 UTC] cmb@php.net
Even if LIBXML_NOCDATA is not passed, the ouput of the second item
is not correct; this is already tracked as bug #61597.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Mar 19 10:01:30 2024 UTC