php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #70905 SimpleXML parses different w/ newlines and w/o newlines after closing ">"
Submitted: 2015-11-13 01:11 UTC Modified: 2018-08-07 15:59 UTC
From: be dot creative at webapper dot hu Assigned: cmb (profile)
Status: Closed Package: SimpleXML related
PHP Version: 5.6.15 OS: Ubuntu 15.04
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: be dot creative at webapper dot hu
New email:
PHP Version: OS:

 

 [2015-11-13 01:11 UTC] be dot creative at webapper dot hu
Description:
------------
Hi, just ran into this interesting bug, unsure if it effects other PHP versions. In the test case below you can see that stripped XML parsed differently than those which are separated by newlines.

Test script:
---------------
<?php
// no indenting and new lines
	$xmlStr = <<<HERE
<?xml version='1.0' encoding='UTF-8'?><ns2RoomRate RatePlanCode="DEF" RatePlanID="0:5:0:0"><ns2Rates><ns2Rate UnitMultiplier="1" /><ns2Rate UnitMultiplier="1"><ns2TPA_Extensions><ns3AccomSupplement AmountAfterTax="109.59" AmountBeforeTax="109.59" BestDiscountGrpNo="0" Compulsory="false" CurrencyCode="USD" ItemRPH="0:5:0:0S0S"><ns2SupplementDescription Name="*replaced*" /></ns3AccomSupplement><ns3AccomSupplement AmountAfterTax="0.00" AmountBeforeTax="0.00" BestDiscountGrpNo="0" Compulsory="true" CurrencyCode="USD" ItemRPH="0:5:0:0S1S"><ns2SupplementDescription Name="Child Extra Bed" /></ns3AccomSupplement></ns2TPA_Extensions></ns2Rate></ns2Rates><ns2RoomRateDescription Name="Buffet Breakfast" /><ns2Total AmountAfterTax="86.52" AmountBeforeTax="86.52" CurrencyCode="USD" /></ns2RoomRate>
HERE;
	$xml = simplexml_load_string($xmlStr);
	echo '<pre>'; print_r($xml); echo '</pre>';
	
// with indenting and new lines
	$xmlStr = <<<HERE
<?xml version='1.0' encoding='UTF-8'?>
<ns2RoomRate RatePlanCode="DEF" RatePlanID="0:5:0:0">
	<ns2Rates>
		<ns2Rate UnitMultiplier="1" />
		<ns2Rate UnitMultiplier="1">
			<ns2TPA_Extensions>
				<ns3AccomSupplement AmountAfterTax="109.59" AmountBeforeTax="109.59" BestDiscountGrpNo="0" Compulsory="false" CurrencyCode="USD" ItemRPH="0:5:0:0S0S">
					<ns2SupplementDescription Name="*replaced*" />
				</ns3AccomSupplement>
				<ns3AccomSupplement AmountAfterTax="0.00" AmountBeforeTax="0.00" BestDiscountGrpNo="0" Compulsory="true" CurrencyCode="USD" ItemRPH="0:5:0:0S1S">
					<ns2SupplementDescription Name="Child Extra Bed" />
				</ns3AccomSupplement>
			</ns2TPA_Extensions>
		</ns2Rate>
	</ns2Rates>
	<ns2RoomRateDescription Name="Buffet Breakfast" />
	<ns2Total AmountAfterTax="86.52" AmountBeforeTax="86.52" CurrencyCode="USD" />
</ns2RoomRate>
HERE;
	$xml = simplexml_load_string($xmlStr);
	echo '<pre>'; print_r($xml); echo '</pre>';

// no indenting and new lines BUT inserting new lines after!
	$xmlStr = <<<HERE
<?xml version='1.0' encoding='UTF-8'?><ns2RoomRate RatePlanCode="DEF" RatePlanID="0:5:0:0"><ns2Rates><ns2Rate UnitMultiplier="1" /><ns2Rate UnitMultiplier="1"><ns2TPA_Extensions><ns3AccomSupplement AmountAfterTax="109.59" AmountBeforeTax="109.59" BestDiscountGrpNo="0" Compulsory="false" CurrencyCode="USD" ItemRPH="0:5:0:0S0S"><ns2SupplementDescription Name="*replaced*" /></ns3AccomSupplement><ns3AccomSupplement AmountAfterTax="0.00" AmountBeforeTax="0.00" BestDiscountGrpNo="0" Compulsory="true" CurrencyCode="USD" ItemRPH="0:5:0:0S1S"><ns2SupplementDescription Name="Child Extra Bed" /></ns3AccomSupplement></ns2TPA_Extensions></ns2Rate></ns2Rates><ns2RoomRateDescription Name="Buffet Breakfast" /><ns2Total AmountAfterTax="86.52" AmountBeforeTax="86.52" CurrencyCode="USD" /></ns2RoomRate>
HERE;
	$xmlStr = str_replace('><', '>'."\n".'<', $xmlStr); // inserting here
	$xml = simplexml_load_string($xmlStr);
	echo '<pre>'; print_r($xml); echo '</pre>';


Expected result:
----------------
SimpleXMLElement Object
(
    [@attributes] => Array
        (
            [RatePlanCode] => DEF
            [RatePlanID] => 0:5:0:0
        )

    [ns2Rates] => SimpleXMLElement Object
        (
            [ns2Rate] => Array
                (
                    [0] => SimpleXMLElement Object
                        (
                            [@attributes] => Array
                                (
                                    [UnitMultiplier] => 1
                                )

                        )

                    [1] => SimpleXMLElement Object
                        (
                            [@attributes] => Array
                                (
                                    [UnitMultiplier] => 1
                                )

                            [ns2TPA_Extensions] => SimpleXMLElement Object
                                (
                                    [ns3AccomSupplement] => Array
                                        (
                                            [0] => SimpleXMLElement Object
                                                (
                                                    [@attributes] => Array
                                                        (
                                                            [AmountAfterTax] => 109.59
                                                            [AmountBeforeTax] => 109.59
                                                            [BestDiscountGrpNo] => 0
                                                            [Compulsory] => false
                                                            [CurrencyCode] => USD
                                                            [ItemRPH] => 0:5:0:0S0S
                                                        )

                                                    [ns2SupplementDescription] => SimpleXMLElement Object
                                                        (
                                                            [@attributes] => Array
                                                                (
                                                                    [Name] => *replaced*
                                                                )

                                                        )

                                                )

                                            [1] => SimpleXMLElement Object
                                                (
                                                    [@attributes] => Array
                                                        (
                                                            [AmountAfterTax] => 0.00
                                                            [AmountBeforeTax] => 0.00
                                                            [BestDiscountGrpNo] => 0
                                                            [Compulsory] => true
                                                            [CurrencyCode] => USD
                                                            [ItemRPH] => 0:5:0:0S1S
                                                        )

                                                    [ns2SupplementDescription] => SimpleXMLElement Object
                                                        (
                                                            [@attributes] => Array
                                                                (
                                                                    [Name] => Child Extra Bed
                                                                )

                                                        )

                                                )

                                        )

                                )

                        )

                )

        )

    [ns2RoomRateDescription] => SimpleXMLElement Object
        (
            [@attributes] => Array
                (
                    [Name] => Buffet Breakfast
                )

        )

    [ns2Total] => SimpleXMLElement Object
        (
            [@attributes] => Array
                (
                    [AmountAfterTax] => 86.52
                    [AmountBeforeTax] => 86.52
                    [CurrencyCode] => USD
                )

        )

)
SimpleXMLElement Object
(
    [@attributes] => Array
        (
            [RatePlanCode] => DEF
            [RatePlanID] => 0:5:0:0
        )

    [ns2Rates] => SimpleXMLElement Object
        (
            [ns2Rate] => Array
                (
                    [0] => SimpleXMLElement Object
                        (
                            [@attributes] => Array
                                (
                                    [UnitMultiplier] => 1
                                )

                        )

                    [1] => SimpleXMLElement Object
                        (
                            [@attributes] => Array
                                (
                                    [UnitMultiplier] => 1
                                )

                            [ns2TPA_Extensions] => SimpleXMLElement Object
                                (
                                    [ns3AccomSupplement] => Array
                                        (
                                            [0] => SimpleXMLElement Object
                                                (
                                                    [@attributes] => Array
                                                        (
                                                            [AmountAfterTax] => 109.59
                                                            [AmountBeforeTax] => 109.59
                                                            [BestDiscountGrpNo] => 0
                                                            [Compulsory] => false
                                                            [CurrencyCode] => USD
                                                            [ItemRPH] => 0:5:0:0S0S
                                                        )

                                                    [ns2SupplementDescription] => SimpleXMLElement Object
                                                        (
                                                            [@attributes] => Array
                                                                (
                                                                    [Name] => *replaced*
                                                                )

                                                        )

                                                )

                                            [1] => SimpleXMLElement Object
                                                (
                                                    [@attributes] => Array
                                                        (
                                                            [AmountAfterTax] => 0.00
                                                            [AmountBeforeTax] => 0.00
                                                            [BestDiscountGrpNo] => 0
                                                            [Compulsory] => true
                                                            [CurrencyCode] => USD
                                                            [ItemRPH] => 0:5:0:0S1S
                                                        )

                                                    [ns2SupplementDescription] => SimpleXMLElement Object
                                                        (
                                                            [@attributes] => Array
                                                                (
                                                                    [Name] => Child Extra Bed
                                                                )

                                                        )

                                                )

                                        )

                                )

                        )

                )

        )

    [ns2RoomRateDescription] => SimpleXMLElement Object
        (
            [@attributes] => Array
                (
                    [Name] => Buffet Breakfast
                )

        )

    [ns2Total] => SimpleXMLElement Object
        (
            [@attributes] => Array
                (
                    [AmountAfterTax] => 86.52
                    [AmountBeforeTax] => 86.52
                    [CurrencyCode] => USD
                )

        )

)
SimpleXMLElement Object
(
    [@attributes] => Array
        (
            [RatePlanCode] => DEF
            [RatePlanID] => 0:5:0:0
        )

    [ns2Rates] => SimpleXMLElement Object
        (
            [ns2Rate] => Array
                (
                    [0] => SimpleXMLElement Object
                        (
                            [@attributes] => Array
                                (
                                    [UnitMultiplier] => 1
                                )

                        )

                    [1] => SimpleXMLElement Object
                        (
                            [@attributes] => Array
                                (
                                    [UnitMultiplier] => 1
                                )

                            [ns2TPA_Extensions] => SimpleXMLElement Object
                                (
                                    [ns3AccomSupplement] => Array
                                        (
                                            [0] => SimpleXMLElement Object
                                                (
                                                    [@attributes] => Array
                                                        (
                                                            [AmountAfterTax] => 109.59
                                                            [AmountBeforeTax] => 109.59
                                                            [BestDiscountGrpNo] => 0
                                                            [Compulsory] => false
                                                            [CurrencyCode] => USD
                                                            [ItemRPH] => 0:5:0:0S0S
                                                        )

                                                    [ns2SupplementDescription] => SimpleXMLElement Object
                                                        (
                                                            [@attributes] => Array
                                                                (
                                                                    [Name] => *replaced*
                                                                )

                                                        )

                                                )

                                            [1] => SimpleXMLElement Object
                                                (
                                                    [@attributes] => Array
                                                        (
                                                            [AmountAfterTax] => 0.00
                                                            [AmountBeforeTax] => 0.00
                                                            [BestDiscountGrpNo] => 0
                                                            [Compulsory] => true
                                                            [CurrencyCode] => USD
                                                            [ItemRPH] => 0:5:0:0S1S
                                                        )

                                                    [ns2SupplementDescription] => SimpleXMLElement Object
                                                        (
                                                            [@attributes] => Array
                                                                (
                                                                    [Name] => Child Extra Bed
                                                                )

                                                        )

                                                )

                                        )

                                )

                        )

                )

        )

    [ns2RoomRateDescription] => SimpleXMLElement Object
        (
            [@attributes] => Array
                (
                    [Name] => Buffet Breakfast
                )

        )

    [ns2Total] => SimpleXMLElement Object
        (
            [@attributes] => Array
                (
                    [AmountAfterTax] => 86.52
                    [AmountBeforeTax] => 86.52
                    [CurrencyCode] => USD
                )

        )

)

Actual result:
--------------
SimpleXMLElement Object
(
    [@attributes] => Array
        (
            [RatePlanCode] => DEF
            [RatePlanID] => 0:5:0:0
        )

    [ns2Rates] => SimpleXMLElement Object
        (
            [ns2Rate] => Array
                (
                    [0] => SimpleXMLElement Object
                        (
                            [@attributes] => Array
                                (
                                    [UnitMultiplier] => 1
                                )

                        )

                    [1] => SimpleXMLElement Object
                        (
                            [@attributes] => Array
                                (
                                    [UnitMultiplier] => 1
                                )

                            [ns2TPA_Extensions] => SimpleXMLElement Object
                                (
                                    [ns3AccomSupplement] => Array
                                        (
                                            [0] => SimpleXMLElement Object
                                                (
                                                    [@attributes] => Array
                                                        (
                                                            [AmountAfterTax] => 109.59
                                                            [AmountBeforeTax] => 109.59
                                                            [BestDiscountGrpNo] => 0
                                                            [Compulsory] => false
                                                            [CurrencyCode] => USD
                                                            [ItemRPH] => 0:5:0:0S0S
                                                        )

                                                    [0] => SimpleXMLElement Object
                                                        (
                                                            [@attributes] => Array
                                                                (
                                                                    [Name] => *replaced*
                                                                )

                                                        )

                                                )

                                            [1] => SimpleXMLElement Object
                                                (
                                                    [@attributes] => Array
                                                        (
                                                            [AmountAfterTax] => 0.00
                                                            [AmountBeforeTax] => 0.00
                                                            [BestDiscountGrpNo] => 0
                                                            [Compulsory] => true
                                                            [CurrencyCode] => USD
                                                            [ItemRPH] => 0:5:0:0S1S
                                                        )

                                                    [ns2SupplementDescription] => SimpleXMLElement Object
                                                        (
                                                            [@attributes] => Array
                                                                (
                                                                    [Name] => Child Extra Bed
                                                                )

                                                        )

                                                )

                                        )

                                )

                        )

                )

        )

    [ns2RoomRateDescription] => SimpleXMLElement Object
        (
            [@attributes] => Array
                (
                    [Name] => Buffet Breakfast
                )

        )

    [ns2Total] => SimpleXMLElement Object
        (
            [@attributes] => Array
                (
                    [AmountAfterTax] => 86.52
                    [AmountBeforeTax] => 86.52
                    [CurrencyCode] => USD
                )

        )

)
SimpleXMLElement Object
(
    [@attributes] => Array
        (
            [RatePlanCode] => DEF
            [RatePlanID] => 0:5:0:0
        )

    [ns2Rates] => SimpleXMLElement Object
        (
            [ns2Rate] => Array
                (
                    [0] => SimpleXMLElement Object
                        (
                            [@attributes] => Array
                                (
                                    [UnitMultiplier] => 1
                                )

                        )

                    [1] => SimpleXMLElement Object
                        (
                            [@attributes] => Array
                                (
                                    [UnitMultiplier] => 1
                                )

                            [ns2TPA_Extensions] => SimpleXMLElement Object
                                (
                                    [ns3AccomSupplement] => Array
                                        (
                                            [0] => SimpleXMLElement Object
                                                (
                                                    [@attributes] => Array
                                                        (
                                                            [AmountAfterTax] => 109.59
                                                            [AmountBeforeTax] => 109.59
                                                            [BestDiscountGrpNo] => 0
                                                            [Compulsory] => false
                                                            [CurrencyCode] => USD
                                                            [ItemRPH] => 0:5:0:0S0S
                                                        )

                                                    [ns2SupplementDescription] => SimpleXMLElement Object
                                                        (
                                                            [@attributes] => Array
                                                                (
                                                                    [Name] => *replaced*
                                                                )

                                                        )

                                                )

                                            [1] => SimpleXMLElement Object
                                                (
                                                    [@attributes] => Array
                                                        (
                                                            [AmountAfterTax] => 0.00
                                                            [AmountBeforeTax] => 0.00
                                                            [BestDiscountGrpNo] => 0
                                                            [Compulsory] => true
                                                            [CurrencyCode] => USD
                                                            [ItemRPH] => 0:5:0:0S1S
                                                        )

                                                    [ns2SupplementDescription] => SimpleXMLElement Object
                                                        (
                                                            [@attributes] => Array
                                                                (
                                                                    [Name] => Child Extra Bed
                                                                )

                                                        )

                                                )

                                        )

                                )

                        )

                )

        )

    [ns2RoomRateDescription] => SimpleXMLElement Object
        (
            [@attributes] => Array
                (
                    [Name] => Buffet Breakfast
                )

        )

    [ns2Total] => SimpleXMLElement Object
        (
            [@attributes] => Array
                (
                    [AmountAfterTax] => 86.52
                    [AmountBeforeTax] => 86.52
                    [CurrencyCode] => USD
                )

        )

)
SimpleXMLElement Object
(
    [@attributes] => Array
        (
            [RatePlanCode] => DEF
            [RatePlanID] => 0:5:0:0
        )

    [ns2Rates] => SimpleXMLElement Object
        (
            [ns2Rate] => Array
                (
                    [0] => SimpleXMLElement Object
                        (
                            [@attributes] => Array
                                (
                                    [UnitMultiplier] => 1
                                )

                        )

                    [1] => SimpleXMLElement Object
                        (
                            [@attributes] => Array
                                (
                                    [UnitMultiplier] => 1
                                )

                            [ns2TPA_Extensions] => SimpleXMLElement Object
                                (
                                    [ns3AccomSupplement] => Array
                                        (
                                            [0] => SimpleXMLElement Object
                                                (
                                                    [@attributes] => Array
                                                        (
                                                            [AmountAfterTax] => 109.59
                                                            [AmountBeforeTax] => 109.59
                                                            [BestDiscountGrpNo] => 0
                                                            [Compulsory] => false
                                                            [CurrencyCode] => USD
                                                            [ItemRPH] => 0:5:0:0S0S
                                                        )

                                                    [ns2SupplementDescription] => SimpleXMLElement Object
                                                        (
                                                            [@attributes] => Array
                                                                (
                                                                    [Name] => *replaced*
                                                                )

                                                        )

                                                )

                                            [1] => SimpleXMLElement Object
                                                (
                                                    [@attributes] => Array
                                                        (
                                                            [AmountAfterTax] => 0.00
                                                            [AmountBeforeTax] => 0.00
                                                            [BestDiscountGrpNo] => 0
                                                            [Compulsory] => true
                                                            [CurrencyCode] => USD
                                                            [ItemRPH] => 0:5:0:0S1S
                                                        )

                                                    [ns2SupplementDescription] => SimpleXMLElement Object
                                                        (
                                                            [@attributes] => Array
                                                                (
                                                                    [Name] => Child Extra Bed
                                                                )

                                                        )

                                                )

                                        )

                                )

                        )

                )

        )

    [ns2RoomRateDescription] => SimpleXMLElement Object
        (
            [@attributes] => Array
                (
                    [Name] => Buffet Breakfast
                )

        )

    [ns2Total] => SimpleXMLElement Object
        (
            [@attributes] => Array
                (
                    [AmountAfterTax] => 86.52
                    [AmountBeforeTax] => 86.52
                    [CurrencyCode] => USD
                )

        )

)

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2018-08-07 15:59 UTC] cmb@php.net
-Status: Open +Status: Closed -Assigned To: +Assigned To: cmb
 [2018-08-07 15:59 UTC] cmb@php.net
This issue appears to have been resolved.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Jul 25 10:01:29 2024 UTC