This documentation is archived and is not being maintained.

XmlDocument.DocumentType Property

Gets the node containing the DOCTYPE declaration.

[Visual Basic]
Public Overridable ReadOnly Property DocumentType As _
   XmlDocumentType
[C#]
public virtual XmlDocumentType DocumentType {get;}
[C++]
public: __property virtual XmlDocumentType* get_DocumentType();
[JScript]
public function get DocumentType() : XmlDocumentType;

Property Value

The XmlNode containing the DocumentType (DOCTYPE declaration).

Remarks

An XmlDocument can have one and only one child with XmlNodeType equal to DocumentType.

Example

[Visual Basic, C#, C++] The following example gets and displays the DOCTYPE declaration for the document.

[Visual Basic] 
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()
        doc.LoadXml("<!DOCTYPE book [<!ENTITY h 'hardcover'>]>" & _
                    "<book genre='novel' ISBN='1-861001-57-5'>" & _
                    "<title>Pride And Prejudice</title>" & _
                    "<style>&h;</style>" & _
                    "</book>")
        
        ' Display the DocumentType.
        Console.WriteLine(doc.DocumentType.OuterXml)
    End Sub 'Main 
End Class 'Sample

[C#] 
using System;
using System.IO;
using System.Xml;

public class Sample
{
  public static void Main()
  {
    // Create the XmlDocument.
    XmlDocument doc = new XmlDocument();
    doc.LoadXml("<!DOCTYPE book [<!ENTITY h 'hardcover'>]>" +
                "<book genre='novel' ISBN='1-861001-57-5'>" +
                "<title>Pride And Prejudice</title>" +
                "<style>&h;</style>" +
                "</book>");

    // Display the DocumentType.
    Console.WriteLine(doc.DocumentType.OuterXml);

  }
}

[C++] 
#using <mscorlib.dll>
#using <System.Xml.dll>
using namespace System;
using namespace System::IO;
using namespace System::Xml;

int main()
{
    // Create the XmlDocument.
    XmlDocument* doc = new XmlDocument();
    doc->LoadXml(S"<!DOCTYPE book [<!ENTITY h 'hardcover'>]>" 
                 S"<book genre='novel' ISBN='1-861001-57-5'>" 
                 S"<title>Pride And Prejudice</title>" 
                 S"<style>&h;</style>" 
                 S"</book>");

    // Display the DocumentType.
    Console::WriteLine(doc->DocumentType->OuterXml);
}

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family

See Also

XmlDocument Class | XmlDocument Members | System.Xml Namespace | XmlDocumentType

Show: