Document Type Definition (DTD) is a grammar (language) that defines the schema (ie data structure) of an XML document.
- defines constraints on the logical structure
- supports the use of predefined storage units (physical structure).
The syntax is a set of markup declarations that define a document type for SGML-family markup languages (SGML, XML, HTML).
DTDs were a precursor to XML schemas and have a similar function, although different capabilities.
- DTD’s describe XML tags with a Regular expression format like person (name, addr, child*).
- DTD’s taken as a whole, are context-free grammar (CFG).
A DTD can be declared:
- inline inside an XML document,
- or as an external reference.
The document type declaration can point to an external subset (a special kind of external entity) containing:
- markup declarations,
- or can contain the markup declarations directly in an internal subset,
- or can do both.
The DTD for a document consists of both subsets taken together.
DTD are context-free grammars