Bug #70570 [Nab->ReO]: json_encode ignores simplexml cdata

From: Date: Tue, 07 Aug 2018 17:38:01 +0000
Subject: Bug #70570 [Nab->ReO]: json_encode ignores simplexml cdata
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-216668@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=70570&edit=1

 ID:                 70570
 Updated by:         cmb@php.net
 Reported by:        cph at osde dot uk
 Summary:            json_encode ignores simplexml cdata
-Status:             Not a bug
+Status:             Re-Opened
 Type:               Bug
 Package:            SimpleXML related
 Operating System:   xubuntu 14
 PHP Version:        5.5.29
-Assigned To:        cmb
+Assigned To:        
 Block user comment: N
 Private report:     N

 New Comment:

> See <http://php.net/manual/en/simplexmlelement.tostring.php>.

Nonsense, sorry!  Re-opening.


Previous Comments:
------------------------------------------------------------------------
[2018-08-07 16:05:18] cmb@php.net

Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to
report
a bug at http://bugs.php.net/how-to-report.php

See <http://php.net/manual/en/simplexmlelement.tostring.php>.

------------------------------------------------------------------------
[2015-09-24 10:17:52] cph at osde dot uk

Description:
------------
json_encode ignores simplexml cdata fields and returns a blank string instead of cdata may be
related to https://bugs.php.net/bug.php?id=54632&edit=2

Test script:
---------------
<?php

$s = <<<EOT
<?xml version="1.0" encoding="UTF-8"?>
<Response>
<Errors>
	<Error>
	<ErrorId>XML999</ErrorId>
	<ErrorText><![CDATA[cvc-complex-type: Invalid content was found starting with XXX. One of
'{XXX}' is expected.]]></ErrorText>
	</Error>
</Errors>
</Response>
EOT;

$xml = simplexml_load_string($s);

echo $xml->Errors->Error->ErrorId.PHP_EOL;
echo $xml->Errors->Error->ErrorText.PHP_EOL;

echo json_encode($xml,JSON_PRETTY_PRINT);


Expected result:
----------------
XML999
cvc-complex-type: Invalid content was found starting with XXX. One of '{XXX}' is expected.
{
    "Errors": {
        "Error": {
            "ErrorId": "XML999",
            "ErrorText": "cvc-complex-type: Invalid content was found starting with
XXX. One of '{XXX}' is expected."
        }
    }
}

Actual result:
--------------
XML999
cvc-complex-type: Invalid content was found starting with XXX. One of '{XXX}' is expected.
{
    "Errors": {
        "Error": {
            "ErrorId": "XML999",
            "ErrorText": {

            }
        }
    }
}


------------------------------------------------------------------------



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


Thread (8 messages)

« previous php.bugs (#216668) next »