Private
Sub
PrettyFormat(
ByVal
XMLNode
As
MSXML2.IXMLDOMNode,
Optional
ByVal
nl
As
Long
)
Const
C_INDENT_SPC
As
Byte
= 2
Dim
xmlChild
As
MSXML2.IXMLDOMElement
If
nl < 0
Then
nl = 0
If
TypeOf
XMLNode
Is
MSXML2.DOMDocument
Then
Call
PrettyFormat(CallByName(XMLNode,
"DocumentElement"
, VbGet), nl)
ElseIf
XMLNode.HasChildNodes
Then
For
Each
xmlChild
In
XMLNode.ChildNodes
If
xmlChild.HasChildNodes
Then
Call
PrettyFormat(xmlChild, nl + 1)
Call
XMLNode.InsertBefore(XMLNode.OwnerDocument.createTextNode(vbNewLine & Space$(C_INDENT_SPC * 1 + (nl))), xmlChild)
Next
Call
XMLNode.appendChild(XMLNode.OwnerDocument.createTextNode(vbNewLine & Space$(C_INDENT_SPC * nl)))
End
If
End
Sub