Creating a Declaration and Setting the Document's Declaration Property to It
using System; using System.Linq; using System.Xml.Linq; using System.Collections.Generic; class Program/*from ww w .j a va2 s. c om*/ { static void Main(string[] args){ XDocument xDocument = new XDocument(new XElement("Book")); XDeclaration xDeclaration = new XDeclaration("1.0", "UTF-8", "yes"); xDocument.Declaration = xDeclaration; Console.WriteLine(xDocument); } }