CSharp - Deleting a Sequence of Nodes with Remove

Description

Deleting a Sequence of Nodes with Remove

Demo

using System;
using System.Linq;
using System.Xml.Linq;
using System.Collections.Generic;

class Program//from  w  ww  . j a  va2  s  .c o m
{
    static void Main(string[] args){
        XDocument xDocument = new XDocument(
          new XElement("Books",
            new XElement("Book",
              new XAttribute("type", "Author"),
              new XElement("FirstName", "Joe"),
              new XElement("LastName", "Ruby")),
            new XElement("Book",
              new XAttribute("type", "Editor"),
              new XElement("FirstName", "PHP"),
              new XElement("LastName", "Python"))));
        
        xDocument.Descendants().Where(e => e.Name == "FirstName").Remove();
        
        Console.WriteLine(xDocument);

    }
}

Result

Related Topic