Bug #70570 [ReO->Ver]: json_encode ignores simplexml cdata
| From: | cmb@php.net | Date: | Fri, 18 Sep 2020 14:46:06 +0000 |
| Subject: | Bug #70570 [ReO->Ver]: json_encode ignores simplexml cdata | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-229074@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: Re-Opened
+Status: Verified
Type: Bug
Package: SimpleXML related
Operating System: xubuntu 14
PHP Version: 5.5.29
Block user comment: N
Private report: N
New Comment:
This is not particularly related to json_encode(), though; cf.
<https://3v4l.org/l6Xmu>.
Previous Comments:
------------------------------------------------------------------------
[2018-08-07 17:38:01] cmb@php.net
> See
> <http://php.net/manual/en/simplexmlelement.tostring.php>.
Nonsense, sorry! Re-opening.
------------------------------------------------------------------------
[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