Chapter 5. Flattening the First Schema

If you look at the structure of the Russian doll-style schema, you’ll see that it follows the structure of the instance document it applies to, as shown in Figure 3-1. Writing the first schema has pretty much been limited to inserting text, element, or attribute elements into the schema each time a text node, element, or attribute was encountered in the instance document. This method of creating schemas can be seen as a serialization of the XML infoset (i.e., of the structure available in the document) and could, therefore, be easily automated.

Tip

Automated serialization is the principle behind Examplotron, a program described in Chapter 14.

There are a couple of drawbacks to modeling documents with the Russian doll-style schemas, however. First, they aren’t modular and therefore become difficult to read and maintain when documents are large or complex. Second, they can’t represent recursive (self-referencing) models. (Lists that may themselves contain lists are a common case of this model.)

The lack of modularity can be seen in a document as simple as the first schema, shown in Example 3-1. There’s a name element that uses the same model within both the character and author elements.

Figure 5-1 shows how, in the first schema, you need to give the definition of what name means in each context:

Two different definitions of name in the same schema
Figure 5-1. Two different definitions of name in the ...

Get RELAX NG 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.