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.

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.