First Patterns
In plain English, the document, shown in Example 3-1 can be described as having:
One
library
element composed of:One or more
book
elements having:An
id
attribute and anavailable
attributeAn
isbn
element composed oftext
A
title
element with anxml:lang
attribute and a text node
One or more
author
elements with:An
id
attributeA
name
elementAn optional
born
elementAn optional
died
element
Zero or more
character
elements with:An
id
attributeA
name
elementAn optional
born
elementA
qualification
element`
The good news—and what makes RELAX NG so easy to learn—is that in its simplest form, RELAX NG is pretty much a way to formalize the previous statements with simple matching rules. Terms described in the plain English description have matching terms in the RELAX NG Schema document that look a lot like XML:
A “library element” matches
<element name="library">...</element>
An “id attribute” matches
<attribute name="id"/>
“One or more” matches
<oneOrMore>...</oneOrMore>
“Zero or more” matches
<zeroOrMore>...</zeroOrMore>
“Text” matches
<text/>
“Optional” matches
<optional>...</optional>
You saw in Chapter 2 that almost every XML structure is a natural pattern for RELAX NG. Further, each RELAX NG element is a pattern; therefore, each RELAX NG pattern matches a structure from the XML document. Let’s now spend some time examining each basic pattern.
The text Pattern
This pattern is the simplest; it simply matches a text node. More precisely, it matches zero or more text nodes. As you’ll ...
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.