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:
![]() |
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.
![]() |
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.
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access

