Name

grammar — Grammar pattern

Synopsis

“grammar” “{” 
grammarContent* “}”

Restrictions

pattern

May be included in

(pattern), attribute, datatypeName param exceptPattern, element, list, mixed, pattern&pattern, pattern*, pattern+, pattern,pattern, pattern?, pattern|pattern

XML syntax equivalent

grammar

Description

The grammar pattern encapsulates the definitions of start and named patterns.

The most common use of grammar is to validate XML documents. In this case, the start pattern specifies which elements can be used as the document root element. The grammar pattern may also be used to write modular schemas. Here, the start pattern specifies which nodes must be matched by the grammar at the location in which it appears in the schema.

In every case, the named patterns defined in a grammar are considered to be local to this grammar. Note that the top-level grammar is implicit for the compact syntax.

Example

grammar { author-element= element author { attribute id {text}, name-element, born-element, died-element? } book-element = element book { attribute id {text}, attribute available {text}, isbn-element, title-element, author-element *, character-element* } born-element = element born {text} character-element = element character { attribute id {text}, name-element, born-element, qualification-element } died-element = element died {text} isbn-element = element isbn {text} name-element = element name {text} qualification-element = element qualification {text} title-element = element title ...

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.