Mega Code Archive

 
Categories / C# / XML LINQ
 

Generates an Empty Element

using System; using System.Linq; using System.Collections; using System.Collections.Generic; using System.Xml; using System.Xml.Linq; public class MainClass {     public static void Main() {         IEnumerable<XElement> elements =           new XElement[] {     new XElement("Book",       new XElement("Name", "J"),       new XElement("Book", "LINQ")),     new XElement("Book",       new XElement("Name", "J"))};         XElement xElement =           new XElement("Books",             elements.Select(e =>              new XElement(e.Name,                new XElement(e.Element("Name").Name, e.Element("Name").Value),                new XElement("Books", e.Elements("Book")))));         Console.WriteLine(xElement);     } }