Bug #69169 [Ver->Dup]: Regression 5.2: simplexml_load_string parse wrongly when xml given in one row
Edit report at https://bugs.php.net/bug.php?id=69169&edit=1
ID: 69169
Updated by: cmb@php.net
Reported by: nadavvin at gmail dot com
Summary: Regression 5.2: simplexml_load_string parse wrongly
when xml given in one row
-Status: Verified
+Status: Duplicate
Type: Bug
Package: SimpleXML related
Operating System: windows,linux
PHP Version: 5.6.6
-Assigned To:
+Assigned To: cmb
Block user comment: N
Private report: N
New Comment:
After further investigation it turned out that this is a duplicate
of bug #66084.
Previous Comments:
------------------------------------------------------------------------
[2015-05-26 12:16:43] cmb@php.net
Related To: Bug #62639
------------------------------------------------------------------------
[2015-03-04 08:24:15] nadavvin at gmail dot com
It's happen also in var_dump, json_encode:
var_dump($simple_xml);
echo json_encode($simple_xml);
http://3v4l.org/RUnot
------------------------------------------------------------------------
[2015-03-03 19:46:01] requinix@php.net
http://3v4l.org/VAjaa
May just be the print_r() output since ->row[0]->item works fine.
http://3v4l.org/UcBUO
------------------------------------------------------------------------
[2015-03-03 10:36:16] nadavvin at gmail dot com
Description:
------------
when remove, new lines and tab from the following XML, it lost tag name in php > 5.2
instead of "item" appear "0".
test and failed in php 5.5.3 (linux), 5.6.6(windows)
work on: php 5.2 windows
There is also difference between 5.5.3 to 5.6.6 (parse wrong in different ways)
Test script:
---------------
<?php
$a = '<?xml version="1.0" encoding="UTF-8"?>
<root a="b">
<row b="y">
<item s="t" />
</row>
<row p="c">
<item y="n" />
</row>
</root>';
$simple_xml = @simplexml_load_string($a);
print_r($simple_xml);
$b = str_replace( array("\n", "\r", "\t"), "", $a );
var_dump($b);
$simple_xml = @simplexml_load_string($b);
print_r($simple_xml);
Expected result:
----------------
SimpleXMLElement Object
(
[@attributes] => Array
(
[a] => b
)
[row] => Array
(
[0] => SimpleXMLElement Object
(
[@attributes] => Array
(
[b] => y
)
[item] => SimpleXMLElement Object
(
[@attributes] => Array
(
[s] => t
)
)
)
[1] => SimpleXMLElement Object
(
[@attributes] => Array
(
[p] => c
)
[item] => SimpleXMLElement Object
(
[@attributes] => Array
(
[y] => n
)
)
)
)
)
Actual result:
--------------
5.6.6:
SimpleXMLElement Object
(
[@attributes] => Array
(
[a] => b
)
[row] => Array
(
[0] => SimpleXMLElement Object
(
[@attributes] => Array
(
[b] => y
)
[0] => SimpleXMLElement Object
(
[@attributes] => Array
(
[s] => t
)
)
)
[1] => SimpleXMLElement Object
(
[@attributes] => Array
(
[p] => c
)
[item] => SimpleXMLElement Object
(
[@attributes] => Array
(
[y] => n
)
)
)
)
)
5.5.3
SimpleXMLElement Object
(
[@attributes] => Array
(
[a] => b
)
[row] => Array
(
[0] => SimpleXMLElement Object
(
[@attributes] => Array
(
[b] => y
)
[0] => SimpleXMLElement Object
(
[@attributes] => Array
(
[s] => t
)
)
)
[1] => SimpleXMLElement Object
(
[@attributes] => Array
(
[p] => c
)
[0] => SimpleXMLElement Object
(
[@attributes] => Array
(
[y] => n
)
)
)
)
)
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=69169&edit=1
Thread (4 messages)