title: VBA - SelectSingleNode retrieves only first node from the list
body: <p>I am using VBA to manipulate XML file. MS Offfice - 2013. I added library - Microsoft XML Version6.0.
  Please find below the xml as well as the code. I am trying to retrieve all the TID's in the xml and write on sheet. But selectsinglenode() is retrieving only the first node. What am I doing wrong? Is there a way to use selectsinglenode to return each TID? Please suggest. Let me know if you need additional information.</p>
  
  
  
  <pre><code>&lt;NDA xmlns="http://www.example.com"&gt;
    &lt;FileHeader&gt;
      &lt;Form&gt;7&lt;/Form&gt;
      &lt;SID&gt;1521&lt;/SID&gt; 
    &lt;/FileHeader&gt;
    &lt;Subdivision&gt;
      &lt;SID&gt;1521&lt;/SID&gt;
      &lt;CID&gt;200&lt;/CID&gt;
      &lt;Version&gt;1&lt;/Version&gt;
    &lt;/Subdivision&gt;
    &lt;BC&gt;
      &lt;BF&gt;
          &lt;BElem&gt;
              &lt;BFountain&gt;
                  &lt;BFeature&gt;
                    &lt;Start&gt;0&lt;/Start&gt;
                    &lt;End&gt;279&lt;/End&gt;
                    &lt;TType&gt;2&lt;/TType&gt;
                    &lt;SLimit&gt;25&lt;/SLimit&gt;
                    &lt;SIT&gt;3&lt;/SIT&gt;
                    &lt;RBTField&gt;0&lt;/RBTField&gt;
                    &lt;RType&gt;1&lt;/RType&gt;
                    &lt;RParam&gt;0&lt;/RParam&gt;
                    &lt;RParamOp&gt;5&lt;/RParamOp&gt;
                    &lt;TID&gt;4015100639&lt;/TID&gt;
                  &lt;/BFeature&gt;
                  &lt;BFeature&gt;
                    &lt;Start&gt;0&lt;/Start&gt;
                    &lt;End&gt;279&lt;/End&gt;
                    &lt;TType&gt;1&lt;/TType&gt;
                    &lt;SLimit&gt;50&lt;/SLimit&gt;
                    &lt;SIT&gt;3&lt;/SIT&gt;
                    &lt;RBTField&gt;0&lt;/RBTField&gt;
                    &lt;RType&gt;2&lt;/RType&gt;
                    &lt;RParam&gt;0&lt;/RParam&gt;
                    &lt;RParamOp&gt;5&lt;/RParamOp&gt;
                    &lt;TID&gt;2850474662&lt;/TID&gt;
                  &lt;/BFeature&gt;
                  &lt;BFeature&gt;
                    &lt;Start&gt;0&lt;/Start&gt;
                    &lt;End&gt;279&lt;/End&gt;
                    &lt;TType&gt;1&lt;/TType&gt;
                    &lt;SLimit&gt;25&lt;/SLimit&gt;
                    &lt;SIT&gt;3&lt;/SIT&gt;
                    &lt;RBTField&gt;0&lt;/RBTField&gt;
                    &lt;RType&gt;1&lt;/RType&gt;
                    &lt;RParam&gt;0&lt;/RParam&gt;
                    &lt;RParamOp&gt;5&lt;/RParamOp&gt;
                    &lt;TID&gt;2563719215&lt;/TID&gt;
                  &lt;/BFeature&gt;
                  &lt;BFeature&gt;
                    &lt;Start&gt;0&lt;/Start&gt;
                    &lt;End&gt;279&lt;/End&gt;
                    &lt;TType&gt;3&lt;/TType&gt;
                    &lt;SLimit&gt;25&lt;/SLimit&gt;
                    &lt;SIT&gt;3&lt;/SIT&gt;
                    &lt;RBTField&gt;0&lt;/RBTField&gt;
                    &lt;RType&gt;1&lt;/RType&gt;
                    &lt;RParam&gt;0&lt;/RParam&gt;
                    &lt;RParamOp&gt;5&lt;/RParamOp&gt;
                    &lt;TID&gt;1962204848&lt;/TID&gt;
              &lt;/BFeature&gt;
            &lt;/BFountain&gt;
          &lt;/BElem&gt;
      &lt;/BF&gt;
      &lt;/BC&gt;  
  &lt;/NDA&gt;
  </code></pre>
  
  <p>Following is the code:</p>
  
  <pre class="lang-vb prettyprint-override"><code>Dim xDoc1 As MSXML2.DOMDocument60
  Dim xNodeList1 As MSXML2.IXMLDOMNodeList
  Dim xNode1 As MSXML2.IXMLDOMNode
  Dim xChildNode1 As MSXML2.IXMLDOMNode
  Dim xpathToExtractRow1 As String, XMLNamespaces1 As String
  Dim wCompareWorksheet As Excel.Worksheet
  Dim sFoundNode As MSXML2.IXMLDOMNode
  
  Set xDoc1 = New MSXML2.DOMDocument60
  xDoc1.async = False
  xDoc1.validateOnParse = False
  XMLNamespaces1 = "xmlns:r='http://www.example.com"
  
  xDoc1.Load ("ABCD.xml")
  xDoc1.setProperty "SelectionNamespaces", XMLNamespaces1
  xDoc1.setProperty "SelectionLanguage", "XPath"
  
  If xDoc1.parseError.ErrorCode &lt;&gt; 0 Then
    Set oErr1 = xDoc1.parseError
    Debug.Print oErr1.reason
  End If
  
  Set xNodeList1 = xDoc1.SelectNodes("/r:NDA/r:BC/r:BF/r:BElem/r:BFountain/r:BFeature")
  
  z=1
  For x = 0 To xNodeList1.Length - 1
      bFirstChild = True
      If xNodeList1.Item(x).HasChildNodes Then
          For i = 0 To xNodeList1.Item(x).ChildNodes.Length - 1
              Set sFoundNode = xNodeList1.Item(x).ChildNodes(i).SelectSingleNode("/r:NDA/r:BC/r:BF/r:BElem/r:BFountain/r:BFeature/r:TID")
              If Not sFoundNode Is Nothing Then
                  wCompareWorksheet.Cells(z, 1) = x &amp; "," &amp; i
  
                  wCompareWorksheet.Cells(z, 4) = sFoundNode.nodeName
                  wCompareWorksheet.Cells(z, 6) = sFoundNode.Text
                  z = z + 1
              Else
                  Debug.Print "sFound is nothing"
              End If
          Next
      End If
  Next
  </code></pre>