Skip to main content
XMLDir

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

Comparison

XSD vs DTD

DTDs came with XML and are still the only way to declare an entity. For anything else, XSD has replaced them — and this is the one comparison this site cannot run.

A DTD can say which elements may contain which, and nothing about what a value is. Everything is text, there is no namespace awareness, and the syntax is not XML — which means a DTD cannot be processed with the tools you use for everything else.

It survives for one reason: entity declarations. There is no other mechanism in XML for defining &myentity;, so a document that needs one carries a DOCTYPE whether or not anybody validates against it. That is also why DOCTYPE is a security surface — the same machinery reaches external resources.

The honest position is: use XSD or RELAX NG to validate, avoid DTDs for anything else, and if you are only emitting a DOCTYPE for entities, consider expanding them before publishing instead.

What actually differs

XSD compared with DTD, one row per aspect
AspectXSDDTD
SyntaxXMLIts own, non-XML
DatatypesFull library with facetsNone. Everything is text
NamespacesCentralNot aware of them at all
EntitiesCannot declare themThe only way to declare one
CardinalityminOccurs and maxOccurs, any numbers?, * and + only
Where it livesA separate document, referenced or suppliedInline in the DOCTYPE, or external
SecurityFetching a schema is the validator's choiceDoorway to external entity and expansion attacks

Why there is no demo

Nothing here to execute

We cannot run DTD validation. The WebAssembly build of libxml2 this site uses has no working DTD validation switch, so a demonstration here would be a claim about a validator nobody ran — and the entire point of these pages is that both sides are executed. The entity half of a DTD does work, and is demonstrated on the glossary pages for the internal subset and general entities.

Which to pick

XSD, when

  • Anything that validates values rather than only shape — which is almost every reason to validate.
  • The vocabulary uses namespaces, which a DTD cannot see.
  • You want the grammar to be processable with ordinary XML tooling.

DTD, when

  • You need to declare general entities. Nothing else in XML can.
  • You are working with a legacy vocabulary — DocBook 4, older publishing chains — whose DTD is the normative definition.

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.