Mega Code Archive

 
Categories / C# / XML LINQ
 

Create a new XElement class from another XElement object

using System; using System.Linq; using System.Xml.Linq; using System.Collections; using System.Collections.Generic; public class MainClass{    public static void Main(){             XElement xmlTree = new XElement("Root",             new XAttribute("Att1", 1),             new XElement("Child1", 1),             new XElement("Child2", 2)         );         XElement treeClone = new XElement(xmlTree);         Console.WriteLine("xmlTree = treeClone: {0}", XNode.DeepEquals(xmlTree, treeClone));         xmlTree.Add(new XElement("Child3", 3));         Console.WriteLine("xmlTree = treeClone: {0}", XNode.DeepEquals(xmlTree, treeClone));     } }