CSharp - Adding a Node to the Beginning of the Specified Node's Child Nodes with AddFirst

Description

Adding a Node to the Beginning of the Specified Node's Child Nodes with AddFirst

Demo

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

class Program/*from  w  w w  . j a v  a  2 s  .  co  m*/
{
    static void Main(string[] args){
              //  A document with one book participant.
              XDocument xDocument = new XDocument(
                new XElement("Books",
                  new XElement("Book",
                    new XAttribute("type", "Author"),
                    new XElement("FirstName", "Joe"),
                    new XElement("LastName", "Ruby"))));
        
              xDocument.Element("Books").AddFirst(
                new XElement("Book",
                  new XAttribute("type", "Editor"),
                  new XElement("FirstName", "PHP"),
                  new XElement("LastName", "Python")));
        
              Console.WriteLine(xDocument);
    }
}

Result

Related Topic