Bug #70570 [NEW]: json_encode ignores simplexml cdata
From: cph at osde dot uk
Operating system: xubuntu 14
PHP version: 5.5.29
Package: SimpleXML related
Bug Type: Bug
Bug description:json_encode ignores simplexml cdata
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 bug report at https://bugs.php.net/bug.php?id=70570&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=70570&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=70570&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=70570&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=70570&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=70570&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=70570&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=70570&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=70570&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=70570&r=support
Expected behavior: https://bugs.php.net/fix.php?id=70570&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=70570&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=70570&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=70570&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=70570&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=70570&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=70570&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=70570&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=70570&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=70570&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=70570&r=mysqlcfg
Thread (8 messages)
- cph at osde dot uk