Back
How to convert XML to JSON and JSON back to XML in Javascript ?
You can do it like this:
function parseXml(xml) { var dom = null; if (window.DOMParser) { try { dom = (new DOMParser()).parseFromString(xml, "text/xml"); } catch (e) { dom = null; } } else if (window.ActiveXObject) { try { dom = new ActiveXObject('Microsoft.XMLDOM'); dom.async = false; if (!dom.loadXML(xml)) // parse error .. window.alert(dom.parseError.reason + dom.parseError.srcText); } catch (e) { dom = null; } } else alert("cannot parse xml string!"); return dom;}
function parseXml(xml) {
var dom = null;
if (window.DOMParser) {
try {
dom = (new DOMParser()).parseFromString(xml, "text/xml");
}
catch (e) { dom = null; }
else if (window.ActiveXObject) {
dom = new ActiveXObject('Microsoft.XMLDOM');
dom.async = false;
if (!dom.loadXML(xml)) // parse error ..
window.alert(dom.parseError.reason + dom.parseError.srcText);
else
alert("cannot parse xml string!");
return dom;
31k questions
32.8k answers
501 comments
693 users