A Document Type Definition (DTD) is a specification-based method for describing the structure and content of XML documents. A DTD defines the rules and constraints for the elements and attributes that can be used in an XML document, as well as their arrangement and hierarchy.
Generally, a DTD defines:
- Elements: The names of elements that can be used in an XML document, along with their possible nesting and relationships to each other.
- Attributes: The attributes that can be associated with individual elements, along with their types and values.
- Entities: Entities are used to define reusable blocks of text, markup, or other elements within a document.
- Notations: Notations describe how non-XML content (such as images or multimedia data) can be embedded within an XML document.
There are two types of DTDs: internal DTDs and external DTDs. An internal DTD is defined within the XML document itself, while an external DTD is stored in a separate file and then referenced via a declaration in the XML document.
DTDs were the initial method for defining the structure of XML documents and are still commonly used today. However, XML schema languages such as XML Schema Definition (XSD) and RelaxNG have in many cases supplanted DTDs as the preferred method for structure definition, as they offer more powerful and flexible capabilities.