What is XML Document Type Definition (DTD)?

A DTD can be considered the grammar for a markup language. It is a set of regulations that specifies the usage of XML markup. It defines elements, an element's attributes and its values, and contains specifications about which elements can be contained in others. DTD can also define entities.

A DTD declares what can, what cannot, and what must be included in its associated xml file. The xml documents DTD is checked by a web browser or other validating mechanism to ensure that the structure of the xml file is absolutely correct

DTD allows your XML files to carry a description of its own format with it. The DTD for the above example looks like this:


	<?xml version="1.0"?>
	<!ELEMENT faq-list (question+)>
	<!ELEMENT question (query, response*)>
	<!ELEMENT query    (#PCDATA)>
	<!ELEMENT response (#PCDATA)>

Notes: