How can I loop through all nodes in an XML file

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
'XML Handling - How can I loop through all nodes in an XML file
 
Option Explicit
Private XMLdoc As MSXML2.DOMDocument40
 
Sub Main()
    Dim oxmlNode As IXMLDOMNode
    Dim oxmlReplacement As IXMLDOMNode
    Set XMLdoc = New DOMDocument40 
    With XMLdoc
        .async = False
        .validateOnParse = False
        .preserveWhiteSpace = False
        .Load "C:\temp\csKanna.xml"
        DebugPrint .childNodes(0)
    End With
End Sub
 
Public Function DebugPrint(aNode As IXMLDOMNode) 
    Dim aChild As IXMLDOMNode
    Debug.Print aNode.nodeName
    If aNode.childNodes.length > 0 Then
        For Each aChild In aNode.childNodes
            Debug.Print aChild 
        Next
    End If
End Function

Tags: , , , , , , , , , , , , , , ,

Leave a Reply