Mega Code Archive

 
Categories / C# / XML LINQ
 

XElement ReplaceAll replaces the child nodes and the attributes of this element

using System; using System.Linq; using System.Xml.Linq; using System.Collections; using System.Collections.Generic; public class MainClass{    public static void Main(){         XElement root = new XElement("Root",             new XElement("Child", "child content")         );                  // ReplaceAll with an XElement object.         root.ReplaceAll(new XElement("NewChild", "n"));         Console.WriteLine(root);             } }