★ XML indent output, the easiest way!
Cuixiping 2005-1-28
Some people in time ask about the indentation of XML.
The online see is the XSLT method on the Menciic E chapter blog (his blog propaganda is good, the famous arrogance is great)
Website:
http://blog.9cbs.net/net_lover/archive/2004/07/27/53601.aspx
Article: Inductation formatting of XML using XSLT
This method can solve the problem, but not only the code is cumbersome, but also a XSL file.
I think it is too trouble.
In fact, everything can be simpler, more convenient!
After the problem is derived from the MSXML DOM call Save method, the changed node will be in one line.
There is no return to turn, and indent, reading is very inconvenient.
You think, Microsoft will not know this problem,
Microsoft is Microsoft after all, he will never don't think of a solution for you!
I didn't look at Microsoft's documentation, I came to toss, and I can easily be more complicated!
I suggest that if you use Microsoft's MSXML, take a look at his document.
I have now laid my code:
★ ASP:
<%
DIM RDR, WRT
SET RDR = Server.createObject ("msxml2.saxxmlreader.4.0")
Set WRT = Server.createObject ("msxml2.mxxmlwriter.4.0")
Wrt.indent = TRUE
Set rdr.contenthandler = WRT
'--------------------------------------------
'You can parse XML files, XmLDom objects, XML strings
'RDR.PARSEURL ("Books.xml");
'rdr.parse (xmldoc);
'rdr.parse ("
'--------------------------------------------
Rdr.Parse "
Response.write ("
Response.write (WRT.Output)
Response.write (" xmp>")
%>
★ JavaScript:
Var rdr = new activXObject ("msxml2.saxxmlreader.4.0");
Var WRT = New ActiveXObject ("MSXML2.MXXMLWRITER.4.0");
WRT.INDENT = TRUE;
Rdr.ContentHandler = WRT;
/ *
* You can resolve XML files, XMLDOM objects, XML strings
* RDR.PARSEURL ("Books.xml");
* Rdr.Parse (XMLDOC);
* rdr.parse ("
Rdr.Parse ("
Alert (WRT.Output);
script>