An XML file in ASP, automatic indentation solution

xiaoxiao2021-03-06  42

When you create a new document in ASP, the new document will not automatically indent, although new documents are well formatted or effective from document content, all documents are in one line, using a notebook or other editing work open new When the file, the browsing file is very inconvenient. The following provides two solutions to the XML in ASP: 1. Ind retransmission formatted using XSL: XSL file:

-------------------------------------------------- -------------------------------------------------- -------------------------------------------------- -------------------------------------------------- ------------------------------------ ASP: <% DIM Xmldoc, Xsldoc, Resultdodim Node, SubnodeEt Xmldoc = Server.createObject ("msxml2.domdocument") xmldoc.async = falsexmldoc.loadxml (" ") 'loading root node

'---------------------- Create a node * start -------------------- SET node = xmldoc.createElement ( "user") set subnode = xmldoc.createElement ( "name") subnode.text = "ssm1226" node.appendChild subnodeset subnode = xmldoc.createElement ( "nickname") subnode.text = "rain man" Node.Appendchild Subnode Subnode = NothingXMLDoc.documentelement.AppendChild NodeSet Node = Nothing '---------------------- Create node * end -------- -------------- SET XSLDOC = Server.createObject ("msxml2.domdocument") xsldoc.async = falsexsldoc.Load Server.mappath ("Transform.xsl") 'Loading Translation XSL File SET resultdoc = server.CreateObject ( "MSXML2.DOMDocument") resultdoc.async = falsexmldoc.transformNodeToObject xsldoc, resultdoc 'conversion set node = resultdoc.createProcessingInstruction ( "xml", "version =' 1.0 'encoding =' utf-8 '") 'Create Declaration Resultdoc.insertbefore Node, Resultdoc.FirstChild' Add Declaration Set Node = NothingResultdoc.save Server.mappath ("Result.xml") 'Save XML file%>

2. Add a chamber to Dom

<% Dim xmldoc, node1, node2set xmldoc = server.CreateObject ( "msxml2.domdocument") xmldoc.async = falsexmlDoc.validateOnParse = falseif not xmldoc.loadXML ( " ") then response.Write xmldoc. Parseerror.reason Response.Endend IF

Response.write xmldoc.xmlresponse.endset node1 = xmldoc.createtextNode (VBCRLF)

Set node2 = xmldoc.createElement ("name") node2.text = "ssm1226"

XMLDoc.documentelement.appendchild node1.clonenode (true) xmldoc.documentelement.appendchild node2Xmldoc.documentelement.Appendchild Node1.clonenode (TRUE)

Xmldoc.save "c: /test.xml"%>

转载请注明原文地址:https://www.9cbs.com/read-112277.html

New Post(0)