XML - Document Type (Definition|Declaration) (DTD)

> Markup Language (ML) > Extensible Markup Language (XML)

1 - About

XML provides a mechanism, the document type declaration:

Document Type Definition (DTD) 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.

A Document Type Definition (DTD) defines the legal building blocks of an XML document. It defines the document structure with a list of legal elements and attributes.

A DTD can be declared inline inside an XML document, or as an external reference.

The document type declaration MUST appear before the first element in the document.

The XML document type declaration contains or points to markup declarations that provide a grammar for a class of documents.

This grammar is known as a document type definition, or DTD.

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


3 - Markup Declaration

A markup declaration is:

These declarations may be contained in whole or in part within parameter entities

4 - Element Relation Ship

Declaration Relationship (Cardinality)
<!ELEMENT master (sub)> One and only once
<!ELEMENT master (sub+)> One or more
<!ELEMENT master (sub*)> Zero or more
<!ELEMENT master (sub?)> Zero or one

5 - Documentation / Reference