Oleg Tkachenko posted an article on his blog
about pretty printing
XML documents using MSXML's SAX implementation. I've taken his example
and reproduced it here with some minor modifications more for my own record keeping
more than anything else:
function PrettyPrintXml(xml)
{
var reader = new ActiveXObject("Msxml2.SAXXMLReader.4.0");
var writer = new ActiveXObject("Msxml2.MXXMLWriter.4.0");
writer.indent = true;
writer.standalone = true;
reader.contentHandler = writer;
reader.putProperty("http://xml.org/sax/properties/lexical-handler", writer);
reader.parse(xml);
return writer.output;
}
And here is a demo:
XmlPrettyPrint.htm
(1.04 KB)