RELAX NG by Eric van der Vlist will be published by O'Reilly & Associates (ISBN: 0596004214)

You are welcome to use our annotation system to give your feedback.


Name

grammar — Grammar pattern

Class:

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 { ... }
      )*
   )
}

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 this case the start pattern defines which elements may be used as the document root element. The grammar pattern may also be used as a way to write modular schemas. In this case , the start pattern defines which nodes must be matched by the grammar where ever it appears in the schema.

In every case, the named patterns defined in a grammar are considered to be 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 name="name">
          <text/>
        </element>
      </define>
      <define name="died-element">
        <element name="died">
          <text/>
        </element>
      </define>
    </grammar>
  </define>

  <element xmlns="http://relaxng.org/ns/structure/1.0" name="university">
   <element name="name">
     <text/>
   </element>
   <grammar>
     <include href="flat.rng"/>
   </grammar>
 </element>

      

Attributes:

datatypeLibrary

The datatypeLibrary attribute defines the default datatype library. The value of datatypeLibrary is inherited.

ns

The ns attribute defines the default namespace for the elements defined in a portion of a schema. The value of ns is inherited.


You are welcome to use our annotation system to give your feedback.
[Annotations for this page]
All text is copyright Eric van der Vlist, Dyomedea. During development, I give permission for non-commercial copying for educational and review purposes. After publication, all text will be released under the Free Software Foundation GFDL.