Mega Code Archive

 
Categories / C# / XML LINQ
 

XDocument DocumentType gets the Document Type Definition (DTD) for this document

using System; using System.Linq; using System.Xml.Linq; using System.Collections; using System.Collections.Generic; public class MainClass{    public static void Main(){         string internalSubset = @"<!ELEMENT Pubs (Book+)>         <!ELEMENT Book (Title, Author)>         <!ELEMENT Title (#PCDATA)>         <!ELEMENT Author (#PCDATA)>";                  string target = "xml-stylesheet";         string data = "href='mystyle.css' title='Compact' type='text/css'";                  XDocument doc = new XDocument(             new XComment("This is a comment."),             new XProcessingInstruction(target, data),             new XDocumentType("Pubs", null, null, internalSubset),             new XElement("Pubs",                  new XElement("Book",                     new XElement("Title", "C#"),                     new XElement("Author", "Name")                 )             ),             new XComment("This is another comment.")         );         doc.Declaration = new XDeclaration("1.0", "utf-8", "true");         Console.WriteLine(doc);                  doc.Save("test.xml");    } }