Friday 9 March 2012

Convert XMLDocument to XML string in JavaScript

Some Chart controls do utilize xml documents for rendering data. If you need to update the data in the chart without a roundtrip to the server the function below can help you extract the xml string, update the content and send the results back to the Chart control.

getXmlString: function (xmlDocument) {
var xmlStr;
if (typeof XMLSerializer != "undefined" && !($.browser.msie && parseInt($.browser.version) == 9)) {
xmlStr = (new XMLSerializer()).serializeToString(xmlDocument);
}
else {
xmlStr = xmlDocument.xml;
}
return xmlStr;
}

No comments:

Post a Comment