title: Delete XElement based on attribute
body: <p>I'm still playing around with xml.  Now I have a file that looks like this:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;Attributes&gt;
   &lt;AttributeSet id="10110"&gt;
    &lt;Attribute id="1"&gt;some text here&lt;/Attribute&gt;
    &lt;Attribute id="2"&gt;some text here&lt;/Attribute&gt;
    &lt;!-- 298 more Attribute nodes follow --&gt;
    &lt;!-- note that the value for the id attribute is numbered consecutively --&gt;
   &lt;/AttributeSet&gt;
  &lt;/Attributes&gt;
  </code></pre>
  
  <p>There are 300 Attribute nodes total, most of which I don't need.  What I'd like to do is remove all Attribute nodes that don't have a specified value for the id attribute.  I have established a string array with about 10 values.  These values represent the attributes that I'd like to keep in the xml.  The rest I'd like to remove.</p>
  
  <p>What I'm trying to do with the code below is modify the xml by removing all Attribute nodes that I don't want to use:</p>
  
  <pre><code>Dim ss() As String = New String() {"39", "41", "38", "111", "148", "222", "256", "270", "283", "284"} 'keep the Attributes whose id value is one of these numbers
  Dim rv As New List(Of String)'will hold Attribute ids to remove
  Dim bool As Boolean = False
  For Each x As XElement In doc...&lt;eb:Attribute&gt;
   For Each s As String In ss
    If x.@id = s Then
     bool = True
     Exit For
    End If
   Next
   If bool = True Then
    'do nothing
   Else 'no attribute matched any of the attribute ids listed mark xelement for removal
    rv.Add(x.@id)
   End If
  Next
  'now remove the xelement
  For Each tr As String In rv
   Dim h As String = tr
   doc...&lt;eb:Attribute&gt;.Where(Function(g) g.@id = h).Remove()
  Next
  'save the xml
  doc.Save("C:\myXMLFile.xml")
  </code></pre>
  
  <p>For some reason, my code doesn't work.  None of the undesired Attribute nodes are removed.</p>
  
  <p>What's the problem?  How can I remove the Attribute nodes whose id attribute values don't match any number in my string array?</p>
  
  <p>Thanks in advance.</p>
  
  <p>P.S. - I hope I made myself clear in describing my problem.</p>