Removing an Array of attributes in XML using c#

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:

 var desiredIds = new[] { "fooo1","attribute2", "attribute3" };

var fullAttributeList = xml.Descendants("Value").Attributes("AttributeID");

//Exception list.... 
var rejectThis = rangeProducts.Descendants("Value").Where(y => desiredIds.Contains((string)y.Attribute("AttributeID")));

foreach (var item in rangeProducts.Descendants("Value").Except(rejectThis))
   item.RemoveAttributes(); //nope.... 

   //What now????????

Source: xml

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.