Skip to main content
XMLDir

Search 309 pages — tools, formats, elements, namespaces, directory, comparisons, XPath, datatypes, glossary, parse errors, schema errors, use cases, blog and product.

Schemas and validity

DTD

The original XML schema language: element and attribute declarations written in their own non-XML syntax, plus the entity declarations nothing else provides.

DTDs are weak as grammars — no datatypes, no namespace awareness, no way to say a value must be a date — and they are the only mechanism for declaring entities. That combination is why they persist in formats that have long since moved to XSD for validation.

For our part, we do not offer DTD validation: the WebAssembly build of libxml2 this site runs has no working DTD validation switch. Entity declarations in the internal subset are still read, because that is the parser's normal behaviour rather than a validation mode.

Defined in
XML 1.0 §2.8
Category
Schemas and validity
Also written
document type definition

Shown, not asserted

All 2 claims are executed on every test run, against the same engines the tools use. If the behaviour changes, the test fails rather than this page quietly becoming wrong.

  • The entity machinery of a DTD works without validation being involved at all.

    document.xml
    <!DOCTYPE x [<!ENTITY ok "yes">]>
    <x>&ok;</x>
    expression
    string(/x)

    What the engine returns

    yes
  • And the element model is not enforced: this document contradicts its own DTD.

    document.xml
    <!DOCTYPE x [<!ELEMENT x (a)>]>
    <x><b/></x>

    What the engine returns

    Well-formed.

What catches people out

  • DTDs are not namespace-aware. A DTD constrains the tag text you write, prefix included, rather than the expanded name.
  • Everything in a DTD is text: there is no way to say an attribute must be a number.
  • Because a DTD can pull in external resources, accepting arbitrary DOCTYPEs is a security decision rather than a parsing one.

Get started

Bring order to the XML your team can't afford to ignore.

Create a free account and get a private workspace to search, validate, diff, and monitor your XML feeds, sitemaps, schemas, and vendor integrations.