XmlDocument.CreateDocumentType Method

Returns a new XmlDocumentType object.

Namespace:  System.Xml
Assembly:  System.Xml (in System.Xml.dll)

<PermissionSetAttribute(SecurityAction.InheritanceDemand, Name := "FullTrust")> _
Public Overridable Function CreateDocumentType ( _
	name As String, _
	publicId As String, _
	systemId As String, _
	internalSubset As String _
) As XmlDocumentType


Type: System.String

Name of the document type.

Type: System.String

The public identifier of the document type or Nothing. You can specify a public URI and also a system identifier to identify the location of the external DTD subset.

Type: System.String

The system identifier of the document type or Nothing. Specifies the URL of the file location for the external DTD subset.

Type: System.String

The DTD internal subset of the document type or Nothing.

Return Value

Type: System.Xml.XmlDocumentType
The new XmlDocumentType.

The returned node will have parsed Entities and Notations collections.

Although this method creates the new object in the context of the document, it does not automatically add the new object to the document tree. To add the new object, you must explicitly call one of the node insert methods.

According to the W3C Extensible Markup Language (XML) 1.0 recommendation (www.w3.org/TR/1998/REC-xml-19980210), DocumentType nodes are only allowed within Document nodes. Each XmlDocument can have only one DocumentType node. The DocumentType node must also be inserted before the root element of the XmlDocument (if the document already has a root element, you cannot add a DocumentType node).

If the passed parameters do not combine to build a valid XmlDocumentType, an exception is thrown.

Notes to Inheritors

This method has an inheritance demand. Full trust is required to override the CreateDocumentType method.

This method is a Microsoft extension to the Document Object Model (DOM).

The following example creates a DocumentType node and adds it to an XML document.

Option Explicit
Option Strict

Imports System
Imports System.IO
Imports System.Xml

Public Class Sample

    Public Shared Sub Main()
        'Create the XmlDocument. 
        Dim doc As New XmlDocument()

        'Create a document type node and   
        'add it to the document. 
        Dim doctype As XmlDocumentType
        doctype = doc.CreateDocumentType("book", Nothing, Nothing, "<!ELEMENT book ANY>")

        'Create the root element and  
        'add it to the document.

        Console.WriteLine("Display the modified XML...")
    End Sub 'Main
End Class 'Sample

.NET Framework

Supported in: 4.6, 4.5, 4, 3.5, 3.0, 2.0, 1.1

.NET Framework Client Profile

Supported in: 4, 3.5 SP1
Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
© 2015 Microsoft