Skip to main content
Shakewell

Comparison

DTD vs XSD vs Schematron: Three Ways to Police a Document

Every structured content standard rests on a validation technology, and the three main ones answer different questions: what may exist, what form it takes, and what your project actually allows.

The Three Layers

Grammar, Types, Rules

DTDs are the grammar layer, inherited straight from SGML: which elements exist, what nests in what, in which order. They built the structured world and still run large parts of it — MIL-STD-40051 deliverables validate against DTDs today. Their blind spot is form: a DTD cannot say a value must be a date, a bounded number, or a pattern. XSD — XML Schema — fixed exactly that: namespace-aware, written in XML, and typed, which is why S1000D's current issues define their data modules with schemas. A data module is half document, half data; its codes and identifiers deserve mechanical checking.

Schematronis the odd one out and the most underused: not a grammar at all, but assertions — XPath rules over the document. “A warning must precede the step it concerns.” “This attribute must come from the project's approved list.” Everything grammars can't see, because it lives between elements rather than inside one.

The Choice

“Valid” Is Not “Compliant”

Standards-governed content under layered validation
The standard mandates the grammar; the project supplies the rules. Both layers, or 'valid' just means 'parseable.'

In practice the grammar layer is rarely your decision — the contract's standard chose it years ago. The decision that isyours is whether validation stops there. A schema-valid document can still break every convention your program holds: the optional element your style guide forbids, the code from the wrong vocabulary, the structure that's legal to the spec and wrong for you. That gap is precisely what S1000D formalizes with the BREX — project rules as data — and what Schematron-style checking enforces in any XML pipeline, S1000D or not.

The pattern to take away is layered enforcement: grammar for structure, types for form, rules for policy — the same triad that makes a content model more than a template. When we build or audit publishing pipelines, the rules layer is where the findings live: almost everyone validates against the mandated grammar, and almost nobody has encoded the decisions that make their content theirs. The technology to do it has been standing by for twenty years.

FAQ

Questions We Hear

What is a DTD, and what can it express?

The Document Type Definition is XML's original validation language, inherited from SGML: it declares which elements exist, what each may contain and in what order, and which attributes they carry. Its limits are equally defining: no namespaces, almost no datatypes (it cannot say an attribute must be a date or a number in a range), and a syntax all its own. It remains in service because decades of standards were built on it — MIL-STD-40051's technical manual deliverables validate against DTDs to this day.

What does XSD add over a DTD?

XML Schema (XSD) is the W3C successor: written in XML itself, namespace-aware, and above all typed — an attribute can be declared a date, an integer within bounds, a string matching a pattern. That makes it the natural fit for content that is partly data, which is why S1000D's current issues define their document types with XML Schemas: a data module is full of codes, dates, and identifiers whose form is worth checking mechanically.

Where does Schematron fit?

Schematron validates rules rather than grammar: assertions written as XPath expressions over the document — 'if the module is procedural, a warning must precede the step it concerns,' 'this code must come from the project's approved list.' It's standardized in the ISO DSDL family and shines exactly where grammars go blind: co-occurrence constraints, cross-element logic, project-specific policy. In S1000D terms, this is the natural home of business-rule checking layered on top of schema validation.

Which one should a project use?

Usually the standard decides the grammar layer for you — a 40051 contract means DTDs, an S1000D program means the spec's schemas. The genuine decision is the rules layer: grammar validation alone accepts every structurally-legal document, including ones that violate your project's own conventions. Mature programs pair the mandated grammar with rule-based checking (Schematron or equivalent, expressing the BREX-style decisions), so 'valid' starts to mean 'compliant with us,' not just 'parseable.'

Get In Touch

Validating Structure but Not Policy?

If your pipeline's only gate is the mandated DTD or schema, your conventions are enforced by review meetings. We build the rules layer that catches drift before humans have to.