What is a DTD?

MSXML 5.0 SDK

Microsoft XML Core Services (MSXML) 5.0 for Microsoft Office - XML Schemas

What is a DTD?

Document type definitions (DTDs) provide a way of writing markup rules that specify how XML documents can be validly created. When XML 1.0 was originally specified, the DTD syntax (which is not XML-based) was inherited mainly from earlier markup languages, such as SGML and HTML.

Support for DTDs has been part of SGML for many years, and unlike XML schemas, DTDs have been widely available for use with XML since the XML 1.0 specification was first published in 1996. Therefore, DTDs are still a widely available and supported grammar for authoring and defining XML document types. Almost all validating XML parsers in wide release provide some built-in support for DTDs when validating and parsing XML documents.

DTDs, however, have the following limitations:

  • Because the syntax is different from XML syntax, it can be difficult to read and write DTDs.
  • DTDs provide very limited support for native data types, and no support for extending and defining custom data types. DTDs only provide for character data as a native data type.
  • DTDs do not support XML namespaces well. Although you can write DTD statements that will allow you to declare an element name that includes namespace prefixes, the process by which DTDs are parsed does not enforce adherence to a namespace. Therefore, if a particular namespace URI must be used within a document.

As an alternative to DTDs, you can describe the XML document structure using XDR-based or XSD-based schemas, which offer the same benefits as DTDs but also resolve some of the limitations of DTDs.

DTDs are mainly useful when you are working with legacy XML applications that require them and do not support XML schemas.

See Also

Introduction to DTD Syntax | Authoring DTDs