XML Auto Indent output

Source: Internet
Author: User
Tags xsl file xslt
¢★xml indent output, the simplest method.
By: Unintentional (cuixiping) 2005-1-28
From time to time someone asks about the indentation of XML.
See online is a lot of Mencius E Chapter blog on the XSLT method (his blog publicity is good, fame big well)
URL: http://blog.csdn.net/net_lover/archive/2004/07/27/53601.aspx
Article: Using XSLT to indent XML for format processing
This approach solves the problem, but not only is the code cumbersome, but it also requires an XSL file.
I think it's too much trouble.
In fact, everything can be simpler and more convenient.
The problem is that after the MSXML DOM calls the Save method, the changed nodes will all be on one line,
No carriage return line and indent, reading is very inconvenient.
You think Microsoft doesn't know that this problem exists,
Microsoft, after all, is Microsoft, and he's not going to think of a solution for you.
Did not look at Microsoft's documents carefully, to the blind toss, can be simple to complicate.
I suggest that if you use Microsoft MSXML, look at his documents.
I'm going to post my code now:
In ★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
'--------------------------------------------
' Can parse XML files, XMLDOM objects, XML strings
' Rdr.parseurl ("books.xml");
' Rdr.parse (xmldoc);
' Rdr.parse ("<article><author> unintentional (cuixiping) </author></article>");
'--------------------------------------------
Rdr.parse "<article><author> Unintentional (cuixiping) </author></article>"
Response.Write ("<xmp>")
Response.Write (Wrt.output)
Response.Write ("</xmp>")
%>
In ★javascript:
<script language= "JavaScript" >
var rdr = new ActiveXObject ("MSXML2. Saxxmlreader.4.0 ");
var wrt = new ActiveXObject ("MSXML2. Mxxmlwriter.4.0 ");
Wrt.indent = true;
Rdr.contenthandler = WRT;
/*
* Can parse XML file, Xmldom object, XML string
* Rdr.parseurl ("books.xml");
* Rdr.parse (xmldoc);
* Rdr.parse ("<article><author> unintentional (cuixiping) </author></article>");
*/
Rdr.parse ("<article><author> unintentional (cuixiping) </author></article>");
alert (wrt.output);
</script>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.