Name

grammar — Grammar pattern

Synopsis

element grammar
{
 (
 attribute ns { text }?,
 attribute datatypeLibrary { xsd:anyURI }?,
 attribute * - (rng:* | local:*) { text }*
 ),
 (
 ( element * - rng:* { ... }* )
 & (
 ( element start { ... } )
 | ( element define { ... } )
 | element div { ... }
 | element include { ... }
 )*
 )
}

Class

pattern

May be included in

attribute, choice, define, element, except, group, interleave, list, mixed, oneOrMore, optional, start, zeroOrMore

Compact 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 these cases, 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. In this case, the start pattern specifies which nodes must be matched by the grammar wherever it appears in the schema.

In every case, the named patterns defined in a grammar are considered local to this grammar.

Example

<grammar xmlns="http://relaxng.org/ns/structure/1.0"> <start> <element name="library"> <oneOrMore> <ref name="book-element"/> </oneOrMore> </element> </start> <define name="author-element"> ... </define> </grammar> <define name="author-element"> <grammar> <start> <element name="author"> <attribute name="id"/> <ref name="name-element"/> <parentRef name="born-element"/> <optional> <ref name="died-element"/> </optional> </element> </start> <define name="name-element"> <element ...

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.