First Patterns
In plain English, the document, shown in Example 3-1 can be described as having:
One
libraryelement composed of:One or more
bookelements having:An
idattribute and anavailableattributeAn
isbnelement composed oftext
A
titleelement with anxml:langattribute and a text node
One or more
authorelements with:An
idattributeA
nameelementAn optional
bornelementAn optional
diedelement
Zero or more
characterelements with:An
idattributeA
nameelementAn optional
bornelementA
qualificationelement`
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 ...
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