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  ww w  .j a  va  2 s  . c  om*/
{
    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