|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2013-02-16 02:18 UTC] Anxiety35 at gmail dot com
[2013-02-16 02:18 UTC] Anxiety35 at gmail dot com
-Summary: SimpleXML improperly parses Elements containing both
text and child elements
+Summary: SimpleXML improperly parses Mixed Content Elements
[2013-02-19 23:40 UTC] Anxiety35 at gmail dot com
-Status: Open
+Status: Closed
[2013-02-19 23:40 UTC] Anxiety35 at gmail dot com
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sun Nov 30 11:00:02 2025 UTC |
Description: ------------ The following is parsed incorrectly by SimpleXML (but is actually somehow valid XML): <?xml version="1.0" standalone="yes"?> <Response> <CustomsID>010912-1 <IsApproved>NO</IsApproved> <ErrorMsg>Electronic refunds...</ErrorMsg> </CustomsID> </Response> Simple XML results in: SimpleXMLElement Object ( [CustomsID] => Array ( [0] => 010912-1 [1] => 010912-2 ) ) All child elements of <CustomsID> get dropped. Test script: --------------- <?php $xml = '<?xml version="1.0" standalone="yes"?> <Response> <CustomsID>010912-1 <IsApproved>NO</IsApproved> <ErrorMsg>Electronic refunds...</ErrorMsg> </CustomsID> <CustomsID>010912-2 <IsApproved>NO</IsApproved> <ErrorMsg>Electronic refunds...</ErrorMsg> </CustomsID> </Response>'; $result = simplexml_load_string($xml); //$result = new SimpleXMLElement($xml); echo "Resulting object: ".print_r($result,true); Expected result: ---------------- // Something Like: Resulting object: SimpleXMLElement Object ( [CustomsID] => Array ( [0] => SimpleXMLElement Object ( [@attributes] => Array ( [CustomsID] => 010912-1 ) [IsApproved] => NO [ErrorMsg] => Electronic refunds... ) [1] => SimpleXMLElement Object ( [@attributes] => Array ( [CustomsID] => 010912-2 ) [IsApproved] => NO [ErrorMsg] => Electronic refunds... ) ) ) // OR Like: Resulting object: SimpleXMLElement Object ( [CustomsID] => Array ( [0] => SimpleXMLElement Object ( [CustomsID] => 010912-1 [IsApproved] => NO [ErrorMsg] => Electronic refunds... ) [1] => SimpleXMLElement Object ( [CustomsID] => 010912-2 [IsApproved] => NO [ErrorMsg] => Electronic refunds... ) ) ) Actual result: -------------- Resulting object: SimpleXMLElement Object ( [CustomsID] => Array ( [0] => 010912-1 [1] => 010912-2 ) )