XML technologies / DocBook / Getting started with DocBook / The schema jungle
(Excerpt from "DocBook-XML: Media-neutral and platform-independent publishing" by Thomas Schraitle)
The DocBook committee officially supports DTD and RELAX NG. W3C Schema was added only for convenience. All schema languages are identical in element and attribute names and structure, but differ in expressive power, as explained below.
Before starting, choose the schema on which to base your documents. DocBook is available in the following variants:
- DTD (Document Type Definition)
As the oldest and most widespread schema language, DTDs are very well supported by XML editors and parsers. Through version 4.5, DocBook was expressed as a DTD; since 5.0, as a RELAX NG schema.
A DTD is a grammar-based schema language. Grammar-based languages focus on the structure of instance documents and define rules to constrain it, such as “Element A consists of …”. A DTD does not support Namespaces and has a limited datatype system applicable only to attributes.
Use a DTD if you do not need data types and your applications support only DTDs.- RELAX NG
RELAX NG is a grammar-based schema language that is easy to learn and write. It supports datatypes in both element content and attributes. Some XML experts consider it simpler and more reliable than W3C Schema. It also has an equivalent compact syntax.
These capabilities led to DocBook 5 being officially expressed in RELAX NG. Use it if your applications support RELAX NG, you need stricter document control, and you want to integrate other RELAX NG schemas into DocBook 5.- Schematron
Schematron has a special role. It is a rule-based schema language. Such languages specify conditions between elements and attributes through rules or algorithms, for example, “Does the attribute
versionexist on the root element?” It is related to XPath and XSLT. It checks an XML document using so-called context-dependent assertions (English: assertions). Schematron is less often used on its own than as a complement to RELAX NG or W3C Schema. Their different syntaxes prevent Schematron and DTDs from sharing the same file.
For DocBook 5, a document is therefore not validated with Schematron separately, but always alongside RELAX NG or W3C Schema. Both DocBook 5 schemas contain Schematron instructions within DocBook elements. These check conditions that are difficult or impossible to express using RELAX NG or W3C Schema alone. For example, DocBook 5 requires an attributeversionon the root element. W3C Schema or RELAX NG can check this condition, but covering all possible combinations is laborious. Schematron is used for this purpose.- W3C schema
W3C XML Schema is a strongly typed schema language. It describes documents from an object-oriented perspective. It provides basic types for constructing more complex datatypes and allows namespace-aware element and attribute declarations.
Use W3C Schema if your applications do not support RELAX NG but you need equivalent capabilities.
Note: Validation differences
Some validation differences arise from the schema language rather than DocBook itself, for example with datatypes. A document may therefore validate against a DTD but not against RELAX NG or W3C Schema, or vice versa. Always validate DocBook 5 against the RELAX NG or W3C schema.
Which schema language and version should you choose? Documentation, environments, objectives, and requirements vary too much for one universally “correct” answer. The following list discusses version and schema language:
- Version: 4.x or 5.x?
DocBook 5 offers advantages over DocBook 4, described in Differences between DocBook 4 and 5. Prefer version 5 for new projects, since version 4 is no longer developed. New elements are added only in version 5 and later. For older projects, consider whether to migrate existing documents to benefit from the newer version.
- Schema language: DTD, RELAX NG, or W3C Schema?
Documents are tied to their processing tools, so your applications partly determine the schema language. If your XML editor does not support RELAX NG, choosing it as your basis makes no sense. Without such restrictions, RELAX NG or W3C Schema is usually preferable. They offer more precise content control through datatypes or Schematron checks. RELAX NG also makes customizing DocBook very easy.
Copyright © 2009 Millin Verlag
You may print the online version for your private use.
Otherwise, this chapter from "DocBook-XML: Medienneutrales und plattformunabhängiges Publizieren" is subject to the same provisions as the printed edition: the work, including all its parts, is protected by copyright. All rights are reserved, including reproduction, translation, microfilming, and storage and processing in electronic systems.
Millin Verlag, Siebengebirgsring 36, 53797 Lohmar, info(at)millin.de
back to top