From: Anxiety35 at gmail dot com
Operating system: Linux
PHP version: 5.4.11
Package: SimpleXML related
Bug Type: Bug
Bug description:SimpleXML improperly parses Elements containing both text and
child elements
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
)
)
--
Edit bug report at https://bugs.php.net/bug.php?id=64222&edit=1
--
Try a snapshot (PHP 5.4):
https://bugs.php.net/fix.php?id=64222&r=trysnapshot54
Try a snapshot (PHP 5.3):
https://bugs.php.net/fix.php?id=64222&r=trysnapshot53
Try a snapshot (trunk):
https://bugs.php.net/fix.php?id=64222&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=64222&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=64222&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=64222&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=64222&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=64222&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=64222&r=support
Expected behavior: https://bugs.php.net/fix.php?id=64222&r=notwrong
Not enough info:
https://bugs.php.net/fix.php?id=64222&r=notenoughinfo
Submitted twice:
https://bugs.php.net/fix.php?id=64222&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=64222&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=64222&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=64222&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=64222&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=64222&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=64222&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=64222&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=64222&r=mysqlcfg