title: Loop through a full XML document
body: <p>I'm looking for a way to loop through all the nodes of my XML document. </p>
  
  <p><strong>XML file sample</strong></p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;root&gt;
      &lt;llnode created="2005-05-24T15:26:24" createdby="42912153" createdbyname="" description="" id="107810306" modified="2008-06-05T16:07:44" name="" objname="" objtype="0" ownedby="42912153" ownedbyname="" parentid="107810295" size="4"&gt;
          &lt;Nickname domain=""/&gt;
          &lt;MajorMinorContainer&gt;false&lt;/MajorMinorContainer&gt;
          &lt;llnode created="2005-05-06T12:54:03" createdby="42912153" createdbyname="" description="" id="107815681" modified="2006-12-04T14:39:51" name="" objname="" objtype="0" ownedby="42912153" ownedbyname="" parentid="107810306" size="0"&gt;
              &lt;Nickname domain=""/&gt;
              &lt;MajorMinorContainer&gt;false&lt;/MajorMinorContainer&gt;
          &lt;/llnode&gt;
          &lt;llnode created="2005-05-06T12:54:31" createdby="42912153" createdbyname="" description="" id="107815683" modified="2006-12-04T14:39:53" name="" objname="" objtype="0" ownedby="42912153" ownedbyname="" parentid="107810306" size="0"&gt;
              &lt;Nickname domain=""/&gt;
              &lt;MajorMinorContainer&gt;false&lt;/MajorMinorContainer&gt;
          &lt;/llnode&gt;
      &lt;/llnode&gt;
      &lt;llnode created="2005-05-24T15:26:24" createdby="42912153" createdbyname="" description="" id="107810306" modified="2008-06-05T16:07:44" name="" objname="" objtype="0" ownedby="42912153" ownedbyname="" parentid="107810295" size="4"&gt;
          &lt;Nickname domain=""/&gt;
          &lt;MajorMinorContainer&gt;false&lt;/MajorMinorContainer&gt;
          &lt;llnode created="2005-05-06T12:54:03" createdby="42912153" createdbyname="" description="" id="107815681" modified="2006-12-04T14:39:51" name="" objname="" objtype="0" ownedby="42912153" ownedbyname="" parentid="107810306" size="0"&gt;
              &lt;Nickname domain=""/&gt;
              &lt;MajorMinorContainer&gt;false&lt;/MajorMinorContainer&gt;
          &lt;/llnode&gt;
          &lt;llnode created="2005-05-06T12:54:31" createdby="42912153" createdbyname="" description="" id="107815683" modified="2006-12-04T14:39:53" name="" objname="" objtype="0" ownedby="42912153" ownedbyname="" parentid="107810306" size="0"&gt;
              &lt;Nickname domain=""/&gt;
              &lt;MajorMinorContainer&gt;false&lt;/MajorMinorContainer&gt;
          &lt;/llnode&gt;
      &lt;/llnode&gt;
  &lt;/root&gt;
  </code></pre>
  
  <p>The document always has the same structure. Each <em>llnode</em> represents a folder. This can go really deep (for the purpose of the above example, the scope is only 2, but it can go up to 10).</p>
  
  <p>How can I loop through all the records? I don't want to put a loop into a loop and then another loop and do this like 20 times to be sure to handle every node. Is there a way to just do a loop of loops?</p>
  
  <p>Below is what I got so far, only working for the actual XML document (scope=2), would need to add as much loops as the scope increases (it shouldn't go over scope=10)</p>
  
  <p><strong>Original VBA</strong> (from original question)</p>
  
  <pre class="lang-vb prettyprint-override"><code>xmlExportDoc = "myXmlDoc.xml"
  
  Set xmlDoc = New MSXML2.DOMDocument
  xmlDoc.Load (xmlExportDoc)
  
  Set xmlNodeList = xmlDoc.SelectNodes("//llnode")
  
  For Each Node In xmlNodeList
     MsgBox "Listing the EXISTING nodes"
     MsgBox Node.nodeName &amp; " " &amp; Node.NodeValue &amp; " " &amp; Node.NodeType
  
     If Node.HasChildNodes() Then
        MsgBox Node.nodeName &amp; "has child nodes"
        Set xmlNodeList2 = Node.ChildNodes
  
        For Each Node2 In oNodeList2
            MsgBox Node2.nodeName &amp; " " &amp; Node2.NodeValue &amp; " " &amp; Node2.NodeType
  
            If Node2.HasChildNodes() Then
               MsgBox Node2.nodeName &amp; "has child nodes"
            End If
        Next
     End If
  Next
  </code></pre>
  
  <p><strong>UPDATED VBA</strong></p>
  
  <pre class="lang-vb prettyprint-override"><code>Private Function xmlParse(n As MSXML2.IXMLDOMNode)
      Dim n2 As MSXML2.IXMLDOMNode
      MsgBox n.nodeName &amp; " " &amp; n.NodeValue &amp; " " &amp; n.NodeType
  
      If n.HasChildNodes() Then
          MsgBox n.nodeName &amp; " has child nodes"
  
          For Each n2 In n.ChildNodes
              xmlParse (n2)
          Next
  
          MsgBox "Done listing child nodes for " &amp; n.nodeName
      End If
  End Function
  </code></pre>
  
  <p>And the code of the event:</p>
  
  <pre class="lang-vb prettyprint-override"><code>    Dim xmlExportDoc As String
      Dim xmlDoc As MSXML2.DOMDocument
      Dim xmlNodeList As MSXML2.IXMLDOMNodeList, xmlNodeList2
      Dim Node As MSXML2.IXMLDOMNode
  
      xmlExportDoc = "http://myserver.com/myDoc.xml"
  
      Set xmlDoc = New MSXML2.DOMDocument
      xmlDoc.async = False
      xmlDoc.Load (xmlExportDoc)
  
      Set xmlNodeList = xmlDoc.SelectNodes("//llnode")
  
      For Each Node In xmlNodeList
          Call xmlParse(Node)
      Next
  </code></pre>
  
  <p>This still don't work, got an error when doing the recursive <code>xmlParse()</code> call because <code>MSXML2.IXMLDOMNode.ChildNodes</code> doesn't seem to be a <code>MSXML2.IXMLDOMNode</code> type.</p>