5.1. Modeling Documents

What do we mean by a "document model?" It defines the documents that can be produced with a language; or, to use XML terminology, the document model determines which documents conform to the language. A document model answers such questions as "Can this element have a title?" or "Does there have to be a price on this element?"

Figure 5.1 illustrates this point. At the top of the figure is a document model (either a DTD or Schema—we don't care which at the moment). The model is a special kind of document, written in a syntax designed to describe XML languages, which explicitly lays out the grammar and vocabulary for a single markup language. We sometimes call the language it describes a document type or XML application. With this model, it's possible to determine whether or not an XML document conforms to the document type.

Figure 5.1. Comparing documents to a model

In addition to the document model, Figure 5.1 shows two documents. These are actual documents someone has written, which we call document instances to distinguish them from the abstraction of a document model. The one on the left conforms to the language described by the document model, but the other one does not. Conforming documents are said to be valid within the context of the language; other documents are invalid.

5.1.1. Do You Need a Document Model?

Now that you know what a document ...

Get Learning XML now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.