Glossary · 3 · Publishing SDKs and structured content
Document type definition (DTD)
Also known as: DTD
German: Dokumenttypdefinition (DTD)
In markup languages, a document type definition (DTD) is a grammar for a class of SGML or XML documents, written as markup declarations, that defines which elements and attributes may occur, how elements may be nested and which entities are available; a document that conforms to the DTD it declares is valid.
- Publishing SDK
- Structured content
- Standards
In one sentence
A document type definition (DTD) is a grammar for a class of SGML or XML documents that defines allowed elements, attributes, nesting and entities.
Example
A DITA topic declares the DITA concept DTD in its document type declaration, and the authoring tool rejects a step element placed inside a paragraph because the DTD does not allow it there.
How it applies
- Publishing SDKs: DTDs are one of the grammars that structured-content toolchains validate against. In XML 1.0 the document type declaration contains or points to markup declarations that provide a grammar for a class of documents; this grammar is the DTD. A document that meets the constraints of its DTD is valid; without that check it can still be well-formed.
- DITA: The DITA 1.3 specification defines coding requirements for its grammar files as DTDs, RELAX NG and XML Schema, including document-type shells that assemble the modules of a document type. Authoring tools and publishing engines use these grammar files for validation and default attribute values.
- Validation in pipelines: Schema validation against the DTD catches structural errors before publishing. Rules a DTD cannot express (for example, co-occurrence constraints or content checks) are added with rule languages such as Schematron.
- Developer and platform SDKs: Configuration and exchange formats in older or SGML-derived ecosystems still ship DTDs; newer formats more often use XML Schema, RELAX NG or JSON Schema (see Schema (data)).
- Documentation: Name the grammar and its version in the publishing documentation and keep the DTD under version control, because specializations and shells change what is valid; see DITA specialization.
DTD vs. XML Schema and RELAX NG
A DTD uses its own non-XML syntax inherited from SGML and has few data types. XML Schema (W3C) and RELAX NG (OASIS, also ISO/IEC 19757-2) are written in XML (RELAX NG also in a compact syntax) and add data types and namespace-aware validation.
External references
- W3C: Extensible Markup Language (XML) 1.0 (Fifth Edition), section 2.8 “Prolog and Document Type Declaration”
- OASIS: DITA Version 1.3 Part 1: Base Edition, Errata 02, section 2.6 on DTD, RELAX NG and XML Schema coding requirements
- RELAX NG: relaxng.org (OASIS specifications; ISO/IEC 19757-2)