Bug #69169 [Opn->Ver]: Regression 5.2: simplexml_load_string parse wrongly when xml given in one row

From: Date: Tue, 03 Mar 2015 19:46:02 +0000
Subject: Bug #69169 [Opn->Ver]: Regression 5.2: simplexml_load_string parse wrongly when xml given in one row
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-191104@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=69169&edit=1

 ID:                 69169
 Updated by:         requinix@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:             Open
+Status:             Verified
 Type:               Bug
 Package:            SimpleXML related
 Operating System:   windows,linux
 PHP Version:        5.6.6
 Block user comment: N
 Private report:     N

 New Comment:

http://3v4l.org/VAjaa

May just be the print_r() output since ->row[0]->item works fine.
http://3v4l.org/UcBUO


Previous Comments:
------------------------------------------------------------------------
[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)

« previous php.bugs (#191104) next »