using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Linq;
namespace ConsoleApplication2
{
class Program
{
static void Main(string[] args)
{
XDocument xDocument = new XDocument(
new XElement("BookParticipants",
new XElement("BookParticipant",
new XAttribute("type", "Author"),
new XElement("FirstName", "Joe", new XElement("name",
new XElement("noot", "the"),
new XElement("iscool", "yes"))),
new XElement("LastName", "Rattz")),
new XElement("BookParticipant",
new XAttribute("type", "Editor"),
new XElement("FirstName", "Ewan", new XElement("name",
new XElement("noot", "the"),
new XElement("iscool", "yes"))),
new XElement("LastName", "Buckingham"))));
xDocument.Descendants("BookParticipants").Where(x => (string)x.Element("FirstName") == "Joe").Remove();
Console.WriteLine(xDocument);
}
}
}
I am trying to remove the joe element using the where clause. But this is not working. is it possible to delete elements using the where clause?