CSharp - Creating Document Types with XDocumentType

Introduction

XML document types are implemented with the XDocumentType class.

Document types are meant to be added to an XML document, not an element.

You can create a document type and add it to an XML document on the fly using functional construction.

Demo

using System;
using System.Linq;
using System.Xml.Linq;
using System.Collections.Generic;

class Program//from  w  ww . j  a v a  2  s. c om
{
    static void Main(string[] args){
      XDocument xDocument = new XDocument(new XDocumentType("Books",
                                                             null,
                                                             "Books.dtd",
                                                             null),
                                          new XElement("Book"));

      Console.WriteLine(xDocument);
    }
}

Result

Related Topics