A Document Type Definition (DTD) describes the structure of the XML document. It defines the rules to which the elements of the document abide, such that it can be parsed and used successfully. It can predefine the element types, child element types, order and number of each element type.

An XML document which conforms to DTD is said to be valid. The DTD rules can be written as a document with extension “.dtd”, and XML document can contain reference to this external DTD file. This is used when many users share a common DTD.  Otherwise, the DTD rules can be used inline in the XML document.

DTD helps to define a standard for exchanging data. This helps the user to validate the data sent to or received from outer world. The elements can be validated to have defined special characters, character strings, parsed character data (#PCDATA), empty (EMPTY), or any (ANY) type of parsable data.

Example of using external DTD in XML document

Example of using inline DTD in XML document

 

›› go to examples ››