title: VB - Read ChildNode line by line where Name equals
body: <p>I am currently stuck with an issue in VB.net using XML. I am trying to grab all of the child nodes from a selected node and return them one by one. </p>
  
  <p>The code is returning the nodes, but it is dumping them all into one message. I am also not able to get it to search by a particular node (Document).</p>
  
  <p><br><br>
  <strong>XML</strong></p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8" standalone="yes"?&gt;
  &lt;Documents&gt;
  &lt;DocType&gt;
      &lt;Document ID="1"&gt;Document Name 1&lt;/Document&gt; 
          &lt;Fields&gt;
              &lt;Field Type="Date"&gt;Field1&lt;/Field&gt;
              &lt;Field Type="TxtBox"&gt;Field2&lt;/Field&gt;
              &lt;Field Type="TxtBox"&gt;Field3&lt;/Field&gt;
          &lt;/Fields&gt;
  &lt;/DocType&gt;
  &lt;DocType&gt;
      &lt;Name ID="2"&gt;Document Name 2&lt;/Name&gt; 
          &lt;Fields&gt;
              &lt;Field Type="Date"&gt;Field1&lt;/Field&gt;
              &lt;Field Type="TxtBox"&gt;Field2&lt;/Field&gt;
              &lt;Field Type="TxtBox"&gt;Field3&lt;/Field&gt;
          &lt;/Fields&gt;
  &lt;/DocType&gt;
  &lt;DocType&gt;
      &lt;Name ID="3"&gt;Document Name 3&lt;/Name&gt;
          &lt;Fields&gt;
              &lt;Field Type="Date"&gt;Field1&lt;/Field&gt;
              &lt;Field Type="TxtBox"&gt;Field2&lt;/Field&gt;
              &lt;Field Type="TxtBox"&gt;Field3&lt;/Field&gt;
              &lt;Field Type="TxtBox"&gt;Field4&lt;/Field&gt;
              &lt;Field Type="TxtBox"&gt;Field5&lt;/Field&gt;
              &lt;Field Type="TxtBox"&gt;Field6&lt;/Field&gt;
              &lt;Field Type="TxtBox"&gt;Field7&lt;/Field&gt;
          &lt;/Fields&gt;
  &lt;/DocType&gt;
  &lt;/Documents&gt;
  </code></pre>
  
  <p><br><br>
  <strong>VB Code</strong></p>
  
  <pre><code>    Dim sd As New XmlDocument()
      Dim sdXML As New FileStream("xmlFile.xml", FileMode.Open, FileAccess.Read)
      Dim sdNode As XmlNodeList
      Dim sdNum As Integer
      Dim sdMSG As String
  
      sd.Load(sdXML)
      sdNode = sd.GetElementsByTagName("DocType")
  
      For sdNum = 0 To sdNode.Count - 1
          sdMSG = sdNode(sdNum).ChildNodes.Item(1).InnerText
  
          ''Show message box
          MsgBox(sdMSG)
  
      Next
  </code></pre>
  
  <p>To recap: I am looking to get a message box for each field in a particular document
  <br><br>
  This is my first time creating / using XML data so please forgive my ugly code.<br><br>
  Thanks for all help given!</p>
  
  <p><strong>UPDATE</strong>  <br>
  I was able to select a particular Document node by using the SelectNodes function Ann L provided below. I am still running into an issue to where the message box is only showing one instance of all fields listed in that box.  <br></p>
  
  <p>The Document I selected was 'Document Name 3'. The message box returned all 7 fields in one box. If possible I am wanting to display 7 different message boxes.  <br></p>
  
  <p>Here is the code I am using...   <br>
  <strong>VB Code</strong>  <br></p>
  
  <pre><code>Dim sd As New XmlDocument()
      Dim sdXML As New FileStream("xmlFile.xml", FileMode.Open, FileAccess.Read)
      Dim sdNode As XmlNodeList
      Dim sdNum As Integer
      Dim Field As Object
  
      sd.Load(sdXML)
      sdNode = sd.SelectNodes("descendant::DocType[Name='Document Name 3']")
  
      For sdNum = 0 To sdNode.Count - 1
  
          For Each Field In sdNode
              MsgBox(sdNode(sdNum).ChildNodes.Item(1).InnerText)
          Next
  
      Next
  </code></pre>