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: 2018-02-07 15:24 UTC
From: victor-vansloun at hotmail dot com Assigned:
Status: Verified Package: SimpleXML related
PHP Version: 7.1.14 OS: Linux, Apache, Plesklin
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [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
 
PHP Copyright © 2001-2019 The PHP Group
All rights reserved.
Last updated: Sun Feb 17 01:01:25 2019 UTC