Chapter 4

Document Type Definitions

WHAT YOU WILL LEARN IN THIS CHAPTER:

  • How to create DTDs
  • How to validate an XML document against a DTD
  • How to use DTDs to create XML documents from multiple files

As you have seen so far, you can write well-formed XML by following a few simple rules. In effect, these rules describe how to determine one of XML’s key characteristics: its structure. Without the rules, the material is ambiguous. But well-formedness only goes so far. Several other technologies are available for validating XML documents, each with their own advantages and disadvantages. Document Type Definitions (DTDs) offer a way of specifying further rules that help in the interpretation of documents and their structure. By using namespaces (see Chapter 3) it’s possible to create unambiguously distinct sets of elements and attributes according the purpose you have in mind. Whether or not they appear in a namespace, such special-purpose sets of terms are sometimes known as vocabularies. You can describe an XML language’s structure and vocabulary in a software-friendly fashion, which can be used to check whether XML documents meet the requirements. This checking is known as validation.

WHAT ARE DOCUMENT TYPE DEFINITIONS?

When the vocabulary and structure of potential XML documents for a given purpose are considered together, you can talk about the type of the documents: the elements and attributes in these documents, and how they interrelate are designed to cover a particular subject ...

Get Beginning XML, 5th Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.