Adding a Node to the Beginning of the Specified Node's Child Nodes with AddFirst
using System; using System.Linq; using System.Xml.Linq; using System.Collections.Generic; class Program// ww w .j a va2 s.c o 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); } }