title: Reading XML File in vb.net - Object reference not set to an instance of an object
body: <p>I have a series of XML files which are formatted the same. I need to parse through and extract values for certain tags. Here is my vb code (Error is noted):</p>
  
  <pre><code>    Dim dt As New DataTable
      Dim newRow As DataRow
      Dim ds As New DataSet
      Dim doc As New Xml.XmlDocument
      doc.Load(TextBox1.Text)
  
      dt.Columns.Add("")
      dt.Columns.Add("")
      dt.Columns.Add("")
      dt.Columns.Add("")
  
      For Each n As XmlNode In doc.SelectNodes("LOG/TYPE")
  
          newRow = dt.NewRow
          newRow(n.Attributes("EVT").Value) = n.InnerText '-&gt; Error: Object reference not set to an instance of an object.
  
      Next
  
      DataGridView1.DataSource = dt
  </code></pre>
  
  <p>Here is the layout of the XML file I am trying to parse:</p>
  
  <pre><code>&lt;LOG&gt;
    &lt;TYPE&gt;
      &lt;CLASS&gt;class&lt;/CLASS&gt; 
      &lt;CODE&gt;code&lt;/CODE&gt; 
      &lt;EVT&gt;evt&lt;/EVT&gt; 
      &lt;SEVERITY&gt;sev&lt;/SEVERITY&gt; 
      &lt;LABEL&gt;label&lt;/LABEL&gt; 
      &lt;ORIGIN&gt;origin&lt;/ORIGIN&gt; 
      &lt;USERNUMBER&gt;user&lt;/USERNUMBER&gt; 
      &lt;USERTEXT&gt;text&lt;/USERTEXT&gt; 
    &lt;/TYPE&gt;
    &lt;TYPE&gt;
      &lt;CLASS&gt;class1&lt;/CLASS&gt; 
      &lt;CODE&gt;code1&lt;/CODE&gt; 
      &lt;EVT&gt;evt1&lt;/EVT&gt; 
      &lt;SEVERITY&gt;sev1&lt;/SEVERITY&gt; 
      &lt;LABEL&gt;label1&lt;/LABEL&gt; 
      &lt;ORIGIN&gt;origin1&lt;/ORIGIN&gt; 
      &lt;USERNUMBER&gt;user1&lt;/USERNUMBER&gt; 
      &lt;USERTEXT&gt;text1&lt;/USERTEXT&gt; 
    &lt;/TYPE&gt;
  &lt;/LOG&gt;
  </code></pre>
  
  <p>The tag values I need for each datagrid row are as follows:</p>
  
  <pre><code>&lt;EVT&gt;
  &lt;SEVERITY&gt;
  &lt;LABEL&gt;
  &lt;ORIGIN&gt;
  </code></pre>
  
  <p>Thanks in advance!</p>