CSharp - Using LINQ to XML API to Create an XML Document and Adding Some Structure

Description

Using LINQ to XML API to Create an XML Document and Adding Some Structure

Demo

using System;
using System.Linq;
using System.Xml.Linq;
using System.Collections.Generic;

class Program/*from   www .j a  va 2 s .  c o  m*/
{
    static void Main(string[] args){
        XDocument xDocument =
      new XDocument(
        new XElement("Books",
          new XElement("Book",
            new XAttribute("type", "Author"),
            new XElement("FirstName", "Joe"),
            new XElement("LastName", "Ruby"))));
    
    Console.WriteLine(xDocument.ToString());
    }
}

Result

Related Topic