Der er flere forskellige løsninger.
Set doc = CreateObject("MSXML.DOMDocument")
Set one1 = doc.CreateElement("one")
one1.AppendChild(doc.CreateTextNode("A"))
Set one2 = doc.CreateElement("one")
one2.appendChild(doc.CreateTextNode("BB"))
Set one3 = doc.CreateElement("one")
one3.appendChild(doc.CreateTextNode("CCC"))
Set root = doc.CreateElement("all")
root.appendChild(one1)
root.appendChild(one2)
root.appendChild(one3)
doc.appendChild(root)
Set xsl = CreateObject("MSXML.DOMDocument")
xsl.Async = False
xsl.Load("fmt.xsl")
s = doc.TransformNode(xsl)
Set xsl = Nothing
Set doc = Nothing
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.OpenTextFile("foobar.xml", 2)
f.Write s
f.close
Set f = Nothing
Set fso = Nothing
' display foobar.xml
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.OpenTextFile("foobar.xml", 1)
alllines = f.ReadAll
f.Close
Set f = Nothing
Set fso = Nothing
WScript.Echo alllines
<xsl:stylesheet xmlns:xsl="
http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="xml" indent="yes" omit-xml-declaration="yes"/>
<xsl:template match="@* | node()">
<xsl:copy>
<xsl:apply-templates select="@* | node()"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
Set doc = CreateObject("MSXML.DOMDocument")
Set one1 = doc.CreateElement("one")
one1.AppendChild(doc.CreateTextNode("A"))
Set one2 = doc.CreateElement("one")
one2.appendChild(doc.CreateTextNode("BB"))
Set one3 = doc.CreateElement("one")
one3.appendChild(doc.CreateTextNode("CCC"))
Set root = doc.CreateElement("all")
root.appendChild(one1)
root.appendChild(one2)
root.appendChild(one3)
doc.appendChild(root)
Set rdr = CreateObject("MSXML2.SAXXMLReader")
Set wrt = CreateObject("MSXML2.MXXMLWriter")
wrt.Indent = True
wrt.OmitXMLDeclaration = True
Set rdr.ContentHandler = wrt
rdr.putProperty "
http://xml.org/sax/properties/lexical-handler", wrt
rdr.Parse doc
s = wrt.Output
Set wrt = Nothing
Set rdr = Nothing
Set doc = Nothing
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.OpenTextFile("foobar.xml", 2)
f.Write s
f.close
Set f = Nothing
Set fso = Nothing
' display foobar.xml
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.OpenTextFile("foobar.xml", 1)
alllines = f.ReadAll
f.Close
Set f = Nothing
Set fso = Nothing
WScript.Echo alllines
Set doc = CreateObject("MSXML.DOMDocument")
Set one1 = doc.CreateElement("one")
one1.AppendChild(doc.CreateTextNode("A"))
Set one2 = doc.CreateElement("one")
one2.appendChild(doc.CreateTextNode("BB"))
Set one3 = doc.CreateElement("one")
one3.appendChild(doc.CreateTextNode("CCC"))
Set root = doc.CreateElement("all")
root.appendChild(doc.CreateTextNode(vbCrLf & " "))
root.appendChild(one1)
root.appendChild(doc.CreateTextNode(vbCrLf & " "))
root.appendChild(one2)
root.appendChild(doc.CreateTextNode(vbCrLf & " "))
root.appendChild(one3)
root.appendChild(doc.CreateTextNode(vbCrLf))
doc.appendChild(root)
doc.Save("foobar.xml")
Set doc = Nothing
' display foobar.xml
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.OpenTextFile("foobar.xml", 1)
alllines = f.ReadAll
f.Close
Set f = Nothing
Set fso = Nothing
WScript.Echo alllines
Den første laver dog ikke indrykning (på trods af at den burde).