Remove an element : XElement « XML LINQ « C# / CSharp Tutorial






using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Xml;
using System.Xml.Linq;
using System.IO;


public class MainClass{

   public static void Main(string[] args){   
      XDocument NewDoc = new XDocument(new XDeclaration("1.0", "utf-8", "yes"),new XElement("Root", "MyDoc"));  
      NewDoc.Element("Root").Add(
            new XElement("One", "Hello"),
            new XElement("Two", "Hello"),
            new XElement("Three", "Goodbye"));

      NewDoc.Element("Root").Element("Two").Remove();
   }
}








31.2.XElement
31.2.1.Parse Load xml from hard coded string
31.2.2.XML Fragments
31.2.3.Get Descendants for a node
31.2.4.Deal with White Spaces
31.2.5.Load xml from string, text file
31.2.6.Remove an element