convert field containig xml to json
i am getting data from a database, one of these fields containts an xml, is it possible to convert this single field to json?
sample data { "id": 27101, "ResponseStatus": "SUCCESS", "RequestTime": "2018-09-19 14:21:48", "ResponseXml": "<?xml version="1.0" encoding="UTF-8"?>\r\n<Envelope xmlns="http://schemas.xmlsoap.org/soap/envelope/"><Header /><Body><from>Jani</from></Body></Envelope>\r\n", "RequestMode": "DSS", "ErrorCode": null, }
i want the ResponseXml field to be converted to json aswell, i also want to keep the other fields
or any other sollution to parse the xml so i have access to the data inside the xml
thx!
There are a couple options:
- Use
parse_xml($ResponseXml);
- Use
xm_perl
orxm_python
. - If the data is simple using a plain regexp might do:
$ResponseXml =~ /\<from\>(?<From>\S+)\<\/from\>/;