What is a Document Type Definition (DTD)?

Posted: (EET/GMT+2)

 

When XML documents are exchanged between applications, it is often useful to verify that they follow an agreed structure. A Document Type Definition (DTD) defines the elements, attributes, and relationships that are allowed within an XML document.

An XML document can reference a DTD using a DOCTYPE declaration. For example:

<!DOCTYPE Customer SYSTEM "customer.dtd">

A simple DTD might define the structure of a customer document as follows:

<!ELEMENT Customer (Name, Address)>
<!ELEMENT Name (#PCDATA)>
<!ELEMENT Address (#PCDATA)>

Applications that support XML validation can compare an XML document against its DTD before processing the data. This helps detect missing elements or incorrectly structured documents.

Although DTDs provide a standard way to describe XML documents, they have limited support for data types. Maybe in the future, we will see new technologies that provide better validation capabilities.