A Document Type Definition (DTD) is used to define the legal building blocks of an XML document. It defines the document structure by specifying which elements and attributes exist. Note that a DTD is about specifying the structure and syntax of XML documents (not their content).
A DTD can be declared inline within an XML document or as an external reference. A DTD is required to appear before the first element in the document.
An XML Document is considered valid if a DTD is associated with it and if the document complies with the DTD.