To change xml to a string or the other way around you can use the following methods depending on the browser being used:
-
For DOM compliant browsers:
var string = (new XMLSerializer()).serializeToString(xmlNode);
For Internet Explorer:
var string = xmlNode.xml;
To go from string to xml use the following function:
//voorbeeld xml: var text="<note>"; text=text+"<content>whatever blablabla</content>"; text=text+"</note>"; function StringtoXML(text){ if (window.ActiveXObject){ var doc=new ActiveXObject('Microsoft.XMLDOM'); doc.async='false'; doc.loadXML(text); } else { var parser=new DOMParser(); var doc=parser.parseFromString(text,'text/xml'); } return doc; } //voorbeeld toepassing: var doc = StringtoXML(text);