The grammar and start Elements
In the
Russian doll-style, the definition of
the root element (in this case, the library
element) is used as a container for the whole schema. When you define
named
patterns, you need a container to embed both the named pattern
definitions and the definition of the root element of the named
patterns. This definition of the root element, as well as definitions
of all the patterns that may be used within it, is what RELAX NG
calls a grammar. It uses the
grammar
element. When you use a grammar element, RELAX NG
requires you to explicitly declare the root element or elements,
using a start
element. An incomplete skeleton of the
structure of the schema defining a pattern
name-element would thus be:
<grammar xmlns="http://relaxng.org/ns/structure/1.0"> <start> <element name="library"> .../... </element> </start> <define name="name-element"> .../... </define> </grammar>
or, using the compact syntax:
grammar {
name-element = .../...
start =
element library {
.../...
}
}In the compact syntax, the grammar pattern is
implicit. You can use it, but it isn’t required.
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