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

From: Date: Tue, 07 Aug 2018 16:05:18 +0000
Subject: Bug #70570 [Opn->Nab]: json_encode ignores simplexml cdata
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-216663@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: Open +Status: Not a bug Type: Bug Package: SimpleXML related Operating System: xubuntu 14 PHP Version: 5.5.29 -Assigned To: +Assigned To: cmb Block user comment: N Private report: N New Comment: 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>. Previous Comments: ------------------------------------------------------------------------ [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

« previous php.bugs (#216663) next »