Get Encoding, Version and standalone from XML declaration in CSharp
Description
The following code shows how to get Encoding, Version and standalone from XML declaration.
Example
/* www . ja va2 s . c om*/
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.Linq;
using System.Reflection;
using System.Xml.Linq;
class Program {
static void Main(string[] args) {
XDocument xml = new XDocument(
new XDeclaration("1.0", "UTF-8", "yes"),
new XDocumentType("Books", null, "Books.dtd", null),
new XProcessingInstruction("Book", "out-of-print"),
new XElement("Books"));
Console.WriteLine("Encoding: {0}", xml.Declaration.Encoding);
Console.WriteLine("Version: {0}", xml.Declaration.Version);
Console.WriteLine("Standalone: {0}", xml.Declaration.Standalone);
}
}