title: Delete a specific XML Element
body: <p>I'd like to delete a whole "TableData" Elemt with a specific ID (ID 10 in this case) from my xml:</p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;DataPaths&gt;
    &lt;TableData&gt;
      &lt;ID&gt;10&lt;/ID&gt;
      &lt;TablePath&gt;C:\Users\Tom\Test.xls&lt;/TablePath&gt;
      &lt;TableName&gt;TestName&lt;/TableName&gt;
      &lt;Mode&gt;TestMode&lt;/Mode&gt;
    &lt;/TableData&gt;
  &lt;/DataPaths&gt;
  </code></pre>
  
  <p>I tried two different solutions and I think I'm almost there.</p>
  
  <p>Solution 1:</p>
  
  <pre class="lang-vb prettyprint-override"><code>Dim XmldocDel As New XmlDocument()
          XmldocDel.Load("" &amp; buildSettingsPath)
          Dim node As XmlNode
          node = XmldocDel.SelectSingleNode("//DataPaths/TableData[ID = '10']")
  
          If MessageBox.Show("Are you sure you want to delete:", MessageBoxButtons.YesNo) = DialogResult.Yes Then
              If node IsNot Nothing Then
              node.ParentNode.RemoveChild(node)
              'node.ParentNode.RemoveAll()
  
              XmldocDel.Save("" &amp; buildSettingsPath)
              Reload()
          Else
              MessageBox.Show("No node found")
          End If
  
          Else
              Exit Sub
          End If
  </code></pre>
  
  <p>I'm getting a null Exception here.</p>
  
  <p>Solution 2:</p>
  
  <pre class="lang-vb prettyprint-override"><code>Dim clientNodes = XmldocDel.SelectNodes("//ID")
          For Each elem As Xml.XmlElement In clientNodes
              If elem.InnerText = "10" Then
                  elem.ParentNode.RemoveChild(elem)
                  Exit For
              End If
          Next
  </code></pre>
  
  <p>This will simply do nothing.</p>