Skip to content
uencoder

DTD

A DTD (Document Type Definition) is the structure-definition mechanism of XML 1.0; it is simpler than XSD but limited, and is written in a special (non-XML) syntax.

Purpose

To provide basic structural validation for XML, defining the allowed elements, attributes, and hierarchy.

Mechanism

<!ELEMENT name (content)> declares elements and children, <!ATTLIST> declares attributes, and <!ENTITY> declares entities. There is no type system (strings only) and no namespaces. Before HTML5, HTML used a DTD.

Use cases

  • HTML 4.01 / XHTML 1.0 DTDs
  • Legacy XML document validation
  • SVG 1.1 DTD
  • Teaching examples

Examples

  • Input
    <!ELEMENT name (#PCDATA)>
    Output
    The name element contains text only

    Element declaration

Common errors

A DTD cannot express modern constraints (types, namespaces)
Migrate to XSD or JSON Schema

Related terms

References