All credit goes to Robert McMurray; I just reworked his script into a function:
Option Explicit
' ****************************************
Function prettyXml(ByVal sDirty)
' ****************************************
' Put whitespace between tags. (Required for XSL transformation.)
' ****************************************
sDirty = Replace(sDirty, "><", ">" & vbCrLf & "<")
' ****************************************
' Create an XSL stylesheet for transformation.
' ****************************************
Dim objXSL : Set objXSL = WScript.CreateObject("Msxml2.DOMDocument")
objXSL.loadXML "<xsl:stylesheet version=""1.0"" xmlns:xsl=""http://www.w3.org/1999/XSL/Transform"">" & _
"<xsl:output method=""xml"" indent=""yes""/>" & _
"<xsl:template match=""/"">" & _
"<xsl:copy-of select="".""/>" & _
"</xsl:template>" & _
"</xsl:stylesheet>"
' ****************************************
' Transform the XML.
' ****************************************
Dim objXML : Set objXML = WScript.CreateObject("Msxml2.DOMDocument")
objXML.loadXml sDirty
objXML.transformNode objXSL
prettyXml = objXML.xml
End Function
Dim sTest : sTest = "<a><b><c/></b></a>"
WScript.Echo sTest
WScript.Echo "----------"
WScript.Echo prettyXml(sTest)
WScript.Quit 0
output:
cscript robmcm-2.vbs
<a><b><c/></b></a>
----------
<a>
<b>
<c/>
</b>
</a>
On 2nd thought:
You shouldn't use the above unless you have studied this.