CSharp - Creating XML Tree via XElement

Description

Creating XML Tree via XElement

Demo

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

class Program//  www .  ja  va 2 s.co m
{
    static void Main(string[] args){
        XElement xBookParticipants =
      new XElement("BookParticipants",
        new XElement("BookParticipant",
          new XAttribute("type", "Author"),
          new XElement("FirstName", "Joe"),
          new XElement("LastName", "Ruby")),
        new XElement("BookParticipant",
                new XAttribute("type", "Editor"),
                new XElement("FirstName", "Ewan"),
                new XElement("LastName", "Buckingham")));
    
          Console.WriteLine(xBookParticipants.ToString());
    }
}

Result

Related Topic