I have an XML response, similar to below, which I need to parse the <message>
out of which is contained within some JSON inside of an attribute. It comes in the form of a string.
"<Response attr1='hello' bar='{ \"int\": 50, \"bool\": false, \"message\":\"< message > Test Message <a href=\"http://www.blah.com\">here</a> < /message >\" }'/>;"
I've found some nice pure Javascript answers such as here which was perfect however, as you can see from the example above, the XML now contains JSON with XML within, and this parser also parses the <a>
and <message>
tags which I need to preserve.
What is the easiest way of going about implementing this? My solution needs to be pure Javascript, no libraries.
EDIT: https://jsfiddle.net/ree3c7w0/ shows my attempt at trying to extract the JSON whilst preserving the XML within the JSON and the only way to do this is to escape the XML within the JSON