title: Removing an Array of attributes in XML using c#
body: <p>I'm trying to edit an xml document to only contain a list of attributes I need. I've created an array of attributes I need but I'm not quite sure how to filter the xml document. Here's what I currently have:</p>
  
  <pre><code>var desiredIds = new[] { "fooo1","attribute2", "attribute3" };
  
  var fullAttributeList = xml.Descendants("Value").Attributes("AttributeID");
  
  //Exception list.... 
  var rejectThis = rangeProducts.Descendants("Value").Where(y =&gt; desiredIds.Contains((string)y.Attribute("AttributeID")));
  
  foreach (var item in rangeProducts.Descendants("Value").Except(rejectThis))
   {
     item.RemoveAttributes(); //nope.... 
  
     //What now????????
   }
  </code></pre>
  
  <p>Here's a sample xml with an example of what I'm trying to achieve.</p>
  
  <pre><code>&lt;Product ID="Sample A" UserTypeID="TYPE_PRD_RANGE"&gt;
    &lt;Values AttributeId = "AAAAAA"&gt;
      &lt;Value AttributeId = "BBBBBB"&gt;Value1&lt;/Value&gt;
      &lt;Value AttributeId = "CCCCCC"&gt;Value2&lt;/Value&gt;
      &lt;Value AttributeId = "DDDDDD"&gt;Value3&lt;/Value&gt;
      &lt;Value AttributeId = "EEEEE"&gt;Value4&lt;/Value&gt;
    &lt;/Values&gt;
    &lt;Product ID="Sample A_1" UserTypeID="SUB_RANGE"&gt;
      &lt;Values AttributeId = "ZZZZZZ"&gt;
        &lt;Value AttributeId = "YYYYYY"&gt;Value1&lt;/Value&gt;
        &lt;Value AttributeId = "CCCCCC"&gt;Value2&lt;/Value&gt;
        &lt;Value AttributeId = "DDDDDD"&gt;Value3&lt;/Value&gt;
        &lt;Value AttributeId = "BBBBBB"&gt;Value4&lt;/Value&gt;
      &lt;/Values&gt;
    &lt;/Product&gt;
    &lt;Product ID="Sample A_1_1" UserTypeID="ITEM"&gt;
      &lt;Values AttributeId = "12345"&gt;
        &lt;Value AttributeId = "N12345"&gt;Value1&lt;/Value&gt;
        &lt;Value AttributeId = "A12345"&gt;Value2&lt;/Value&gt;
        &lt;Value AttributeId = "C12345"&gt;Value3&lt;/Value&gt;
        &lt;Value AttributeId = "F12345"&gt;Value4&lt;/Value&gt;
      &lt;/Values&gt;
    &lt;/Product&gt;    
  &lt;/Product&gt;
  </code></pre>
  
  <p>There's a nested xml file with nested nodes being named with the same name <code>Product</code> I need some attributes in the first, second and third nodes so a sample output would be:</p>
  
  <pre><code>&lt;Product ID="Sample A" UserTypeID="TYPE_PRD_RANGE"&gt;
    &lt;Value AttributeId = "DDDDDD"&gt;Value3&lt;/Value&gt;
    &lt;Value AttributeId = "EEEEE"&gt;Value4&lt;/Value&gt;
    &lt;Product ID="Sample A_1" UserTypeID="SUB_RANGE"&gt;
      &lt;Value AttributeId = "BBBBBB"&gt;Value4&lt;/Value&gt;    
    &lt;/Product&gt;
    &lt;Product ID="Sample A_1_1" UserTypeID="ITEM"&gt;
      &lt;Value AttributeId = "F12345"&gt;Value4&lt;/Value&gt;
    &lt;/Product&gt;
  &lt;/Product&gt;
  </code></pre>