DTDs vs Modern Schemas

DTDs versus Modern Schema Languages

DTDs live on in DocBook, JATS and old B2B feeds. For new work, choose by what you must check:

The four schema languages compared
Feature DTD XSD 1.1 RELAX NG Schematron
Syntax Own, non-XML XML XML or compact XML
Data types None Built-in, facets XSD's, via library XPath values
Namespaces Literal prefixes Full Full Full
Cross-field rules No Assertions Limited Main purpose
Free validators Every parser xmlschema 476 , Xerces 129 Jing 258 SchXslt 29

Pair a grammar (XSD when partners publish one, RELAX NG for your own) with Schematron for business rules. Trang (github.com/relaxng/jing-trang (https://github.com/relaxng/jing-trang 258 )) converts a DTD to RELAX NG or XSD, so retiring a legacy DTD is a small job.


Schema Languages

A grammar-based schema language, such as DTD or Relax NG, declares the grammar for an XML document. It defines the permissible structures, contents, and orders of the elements, attributes, and entities.

A rule-based schema language, such as Schematron, specifies the relationships that must hold for the values of elements and attributes.

Very expressive, XSD is both grammar-based and rule-based.
Expressive power vs ease of use for DTD, Relax NG, Schematron, and XML Schema

An XML document that conforms to the schema defined in a schema language is said to be valid.

An XML document can be validated online using tools such as: Offline validation tools include:
This chapter covers the following schema languages: