Edit report at https://bugs.php.net/bug.php?id=64222&edit=1

 ID:                 64222
 User updated by:    Anxiety35 at gmail dot com
 Reported by:        Anxiety35 at gmail dot com
-Summary:            SimpleXML improperly parses Elements containing both
                     text and child elements
+Summary:            SimpleXML improperly parses Mixed Content Elements
 Status:             Open
 Type:               Bug
 Package:            SimpleXML related
 Operating System:   Linux
 PHP Version:        5.4.11
 Block user comment: N
 Private report:     N

 New Comment:

As described in the XML Specs section 3.2.2 titled "Mixed Content"
Spec: www.w3.org/TR/REC-xml/

w3.org is down at the time of posting this comment. Hopefully it's back up soon.


Previous Comments:
------------------------------------------------------------------------
[2013-02-16 01:07:31] Anxiety35 at gmail dot com

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 this bug report at https://bugs.php.net/bug.php?id=64222&edit=1

Reply via email to