A Simple Example

Let’s take a look at an example. Figure 2-1 shows the book element with its two attributes and four different subelements:

A complete example of the book element
Figure 2-1. A complete example of the book element

With a DTD and, to a lesser extent, with W3C XML Schema, you are stuck defining lists of attributes and elements you can’t mix or combine. W3C XML Schema has introduced the concept of types, abstract descriptions that have no direct corollary in the contents of XML documents. Types provide descriptions of the contents of elements or attributes, but types still can’t be freely combined together. This means that you can split the description of elements into blocks such as those shown in Figure 2-2, but can mix the blocks in a limited number of ways.

The blocks of the book element, seen from a W3C XML Schema perspective
Figure 2-2. The blocks of the book element, seen from a W3C XML Schema perspective

RELAX NG patterns, however, can freely mix different types of nodes (elements, text and attributes). Figure 2-3 shows how, if you want to, you can use RELAX NG to split the definition of the book element into a first pattern composed of the attributes id, title, and author and the element character, and then a second pattern composed of the available attribute and the other character elements.

An alternate approach to the document structure, made possible with RELAX NG
Figure 2-3. An alternate approach to the document structure, made possible with RELAX NG

The flexibility just demonstrated isn’t only useful for combining complex patterns. It also maintains the simplicity desired by RELAX NG schema designers who don’t need or want to learn a long list of design limitations that must be checked when they write and combine their schemas.

This generic concept of patterns is powerful enough to replace the specialized containers of DTDs and W3C XML Schema. RELAX NG has no need for (and no notion of ) specially reusable components. Elements, attributes, and types are all embedded in patterns. These patterns are the reusable building blocks of RELAX NG. They can be named, reused, and even redefined at will, combined through operators to group them or to provide alternatives among them.

The benefit of having nonspecialized patterns is increased flexibility. These benefits are similar to those seen in manufacturing: repeatedly using a small number of generic parts to create a unique whole provides more flexibility and a higher number of possible combinations than using more specialized pieces. This works for XML schema languages, too.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.128.18.237