title: How do I properly loop through all XML nodes?
body: <p>I have an XML document which I would like to use the attributes from each node with a structure like so:</p>
  
  <pre><code>&lt;level1 attr1="value" attr2="value"&gt;
     &lt;level2 attr3="value"&gt;
        &lt;level3 attr1="value" attr3="value"&gt;
        &lt;/level3&gt;
      &lt;/level2&gt;
     &lt;level2 attr3="value"&gt;
        &lt;level3 attr1="value" attr3="value"&gt;
        &lt;/level3&gt;
     &lt;/level2&gt;
     &lt;level2 attr3="value"&gt;
        &lt;level3 attr1="value" attr3="value"&gt;
        &lt;/level3&gt;
     &lt;/level2&gt;
  &lt;/level1&gt;
  &lt;level1&gt;
      ....
  &lt;/level1&gt;
  </code></pre>
  
  <p>I am trying to loop through each node in the file and record the information from the attributes.  </p>
  
  <p>Code:</p>
  
  <pre><code>Dim xml As New XDocument
  Dim root As New XElement
  xml = XDocument.Load(myFileLoc)
  root = xml.Root
  
  For Each level1 in root.Descendants()
      'Do Something with level1 attr'
      For Each level2 in level1.Descendants()
          'Do Something with level2 attr'
           For Each level3 in level2.Descendants()
               'Do Something with level3 attr'
           Next
      Next
  Next
  </code></pre>
  
  <p>I learned quickly that this will loop through the entire document several times because level1 in <code>root.Descendants()</code> will also be all children level2s and level3s.  </p>
  
  <p>How can I limit each level1/level2/level3 to only the current node depth?  Or, how should I be doing this kind of work?</p>