Mega Code Archive

 
Categories / C# / XML LINQ
 

Create an XElement class with the specified name and content

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;                  root = new XElement("Root", "Some text");         Console.WriteLine(root);                  root = new XElement("Root", new XElement("NewChild", "n"));         Console.WriteLine(root);                  root = new XElement("Root", new XAttribute("NewAttribute", "n"));         Console.WriteLine(root);                  double dbl = 12.1;         root = new XElement("Root", dbl);         Console.WriteLine(root);                  DateTime dt = new DateTime(2010, 10, 6, 12, 30, 00);         root = new XElement("Root", dt);         Console.WriteLine(root);                  string[] stringArray = {"abc","def","ghi"};         root = new XElement("Root", stringArray);         Console.WriteLine(root);                  XElement[] ellArray = {             new XElement("NewChild1", 1),             new XElement("NewChild3", 3)         };         root = new XElement("Root", ellArray);         Console.WriteLine(root);                  XAttribute[] attArray = {             new XAttribute("NewAtt1", 1),             new XAttribute("NewAtt2", 2),             new XAttribute("NewAtt3", 3)         };         root = new XElement("Root", attArray);         Console.WriteLine(root);     } }