Bug #70570 [Com]: json_encode ignores simplexml cdata

From: Date: Mon, 25 Oct 2021 23:01:41 +0000
Subject: Bug #70570 [Com]: json_encode ignores simplexml cdata
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-237377@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
 Comment by:         wezo dot 203064 at gmail dot com
 Reported by:        cph at osde dot uk
 Summary:            json_encode ignores simplexml cdata
 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:

<a href="https://alfarescleaningservice.business.site/?m=true">تنظيف
مجالس </a>


Previous Comments:
------------------------------------------------------------------------
[2020-09-18 14:46:06] cmb@php.net

This is not particularly related to json_encode(), though; cf.
<https://3v4l.org/l6Xmu>.

------------------------------------------------------------------------
[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


Thread (8 messages)

« previous php.bugs (#237377) next »