Bug #52463 [Com]: SimpleXml ignores attributes
| From: | nm at lindenvalley dot de | Date: | Wed, 19 Jun 2013 07:27:47 +0000 |
| Subject: | Bug #52463 [Com]: SimpleXml ignores attributes | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-179616@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=52463&edit=1
ID: 52463
Comment by: nm at lindenvalley dot de
Reported by: circus2 at freenet dot de
Summary: SimpleXml ignores attributes
Status: Duplicate
Type: Bug
Package: SimpleXML related
Operating System: Win7 Home Premium GER
PHP Version: 5.3.3
Block user comment: N
Private report: N
New Comment:
have same problem, it's not var_dump error, because print_r has same trouble
code:
$xmlObj = simplexml_load_string($xml_string);
print_r ($xmlObj);
Previous Comments:
------------------------------------------------------------------------
[2010-07-28 07:14:28] circus2 at freenet dot de
I'm not concerned about var_dump(). I think more of json_encode() which has the same issues. I
use json_encode/json_decode to transform a SimpleXml object to an array.
print_r(json_decode(json_encode($xml), true)));
------------------------------------------------------------------------
[2010-07-27 23:10:27] rasmus@php.net
This is a known cosmetic issue in var_dump(). If you actually iterate through the
object it works fine.
------------------------------------------------------------------------
[2010-07-27 21:26:21] circus2 at freenet dot de
Description:
------------
I have a short xml and the attributes for the second node are not available.
Test script:
---------------
$xml = '
<xml>
<value type="string" key="name"></value>
<value type="string" key="name">myValue</value>
</xml>
';
var_dump(simplexml_load_string($xml));
Expected result:
----------------
Array
(
[value] => Array
(
[0] => Array
(
[@attributes] => Array
(
[type] => string
[key] => name
)
)
[1] => Array
(
[@attributes] => Array
(
[type] => string
[key] => name
)
[0] => myValue
)
)
)
Or something similar.
Actual result:
--------------
Array
(
[value] => Array
(
[0] => Array
(
[@attributes] => Array
(
[type] => string
[key] => name
)
)
[1] => myValue
)
)
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=52463&edit=1