php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #54937 SIMPLEXML fails to parse correctly
Submitted: 2011-05-27 08:25 UTC Modified: 2011-05-27 15:23 UTC
From: glen2023 at gmail dot com Assigned:
Status: Not a bug Package: Class/Object related
PHP Version: 5.2.17 OS: linux ubuntu 8.10
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: glen2023 at gmail dot com
New email:
PHP Version: OS:

 

 [2011-05-27 08:25 UTC] glen2023 at gmail dot com
Description:
------------
---
From manual page: http://www.php.net/book.simplexml
---

As far as I know, object nodes can only have characters (a-zA-Z0-9_). I think 
problem is created when SIMPLEXML uses @ in @attributes nodes.

It works most of the time, but a node attribute is lost for certain xml data like 
I demonstrated below.



Test script:
---------------
$xml =<<<ENDOF
<root>
      <zakara ee="rr1">
        <xx>aa1</xx>
        <xx plop="huhuD">aa4</xx>
      </zakara>
</root>
ENDOF;

$obj=simplexml_load_string($xml,'SimpleXMLElement', LIBXML_NOCDATA|LIBXML_NOBLANKS|LIBXML_NOERROR|LIBXML_NOWARNING);
	if (!$obj) die();

print_r($obj);

 [plop] => huhuD dissapears.

 

Expected result:
----------------
Array
(
    [zakara] => Array
        (
            [@attributes] => Array
                (
                    [ee] => rr1
                )

            [xx] => Array
                (
                    [0] => aa1
                    [1] => 
                    (            
                      [@attributes] => Array
                       (
                        [plop] => huhuD
                       )
                      [0]=> aa4
                 )
                )

        )

)

Actual result:
--------------
Array
(
    [zakara] => Array
        (
            [@attributes] => Array
                (
                    [ee] => rr1
                )

            [xx] => Array
                (
                    [0] => aa1
                    [1] => aa4
                )

        )

)

Patches

short.xml (last revision 2011-05-27 06:27 UTC by glen2023 at gmail dot com)

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2011-05-27 15:23 UTC] salathe@php.net
-Status: Open +Status: Bogus
 [2011-05-27 15:23 UTC] salathe@php.net
The attribute is not lost forever, it is just that print_r() does not display it.  
Attributes are accessible via the array-style syntax [1] or attributes() method 
[2].

[1] http://php.net/simplexml.examples-basic
[2] http://php.net/simplexmlelement.attributes
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Oct 31 23:01:28 2024 UTC