Would really appreciate some help with this one. The below code removes an element from an XML if it contains the Deleted = true attribute. This works perfectly fine except it only removes the first match. I would like it to remove ALL the Object elements with the attribute condition Deleted = true
public static string TestMethod1(string xmlpath)
XmlDocument xmlfile = new XmlDocument();
xmlfile.Load(xmlpath);
string xmlcontents = xmlfile.InnerXml;
XDocument doc = XDocument.Parse(xmlcontents);
doc.Descendants("Object")
.Where(x => x.Attribute("Deleted").Value == "true").FirstOrDefault()
.Remove();
doc.Save(outputpath);
string docstring = doc.ToString();
return docstring;