Bug #70905 [Opn->Csd]: SimpleXML parses different w/ newlines and w/o newlines after closing ">"

From: Date: Tue, 07 Aug 2018 15:59:55 +0000
Subject: Bug #70905 [Opn->Csd]: SimpleXML parses different w/ newlines and w/o newlines after closing ">"
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-216662@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=70905&edit=1 ID: 70905 Updated by: cmb@php.net Reported by: be dot creative at webapper dot hu Summary: SimpleXML parses different w/ newlines and w/o newlines after closing ">" -Status: Open +Status: Closed Type: Bug Package: SimpleXML related Operating System: Ubuntu 15.04 PHP Version: 5.6.15 -Assigned To: +Assigned To: cmb Block user comment: N Private report: N New Comment: This issue appears to have been resolved. Previous Comments: ------------------------------------------------------------------------ [2016-07-17 18:02:12] cmb@php.net Related To: Bug #71526 ------------------------------------------------------------------------ [2015-11-13 01:11:14] 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 ) ) ) ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=70905&edit=1

« previous php.bugs (#216662) next »