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// w  w  w .j av  a2s  . 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