I have written a REST Api using slim framework 3, and returning response in JSON like this,
return $response->withHeader(
'Content-type',
'application/json; charset=utf-8'
)->withJson($data, 200);
which is working fine.
$xml = '<?xml version="1.0" encoding="UTF-8"?><dialog createdBy=""createDate=""><dialog>' // looks like this
$data = [
'name' => 'xmlName',
'xml' => $xml // fetching from db
]
Now, I have xml string stored in database and want to send it to the client end, I have to save that xml string as in another database as it is.
But when I encode xml string, my json gets break.
I have also tried like,
json_encode($data, JSON_HEX_TAG);
which converts my xml to.
"\u003C?xml version=\"1.0\" encoding=\"UTF-8\"?\u003E
\u003Cdialog createdBy=\"\"
How can I correctly encode the xml in JSON and then get back the original xml string as it is?
Your feedback is much appreciated.