CSharp - Creating a Declaration and Setting the Document's Declaration Property to It

Description

Creating a Declaration and Setting the Document's Declaration Property to It

Demo

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);
    }
}

Result

Related Topic