by Eric van der Vlist is published by O'Reilly & Associates (ISBN: 0596004214)


Name

define — Named pattern definition

Synopsis

element define
{
 attribute name { xsd:NCName },
 ( attribute combine { "choice" | "interleave" }? ),
 (
 attribute ns { text }?,
 attribute datatypeLibrary { xsd:anyURI }?,
 attribute * - (rng:* | local:*) { text }*
 ),
 (
 ( element * - rng:* { ... }* )
 & (
 element element { ... }
 | element attribute { ... }
 | element group { ... }
 | element interleave { ... }
 | element choice { ... }
 | element optional { ... }
 | element zeroOrMore { ... }
 | element oneOrMore { ... }
 | element list { ... }
 | element mixed { ... }
 | element ref { ... }
 | element parentRef { ... }
 | element empty { ... }
 | element text { ... }
 | element value { ... }
 | element data { ... }
 | element notAllowed { ... }
 | element externalRef { ... }
 | element grammar { ... }
 )+
 )
}

Class

define-element

May be included in

div, grammar, include

Compact syntax equivalent

identifier assignMethod pattern

Description

When define is embedded in a grammar, it defines a named pattern or combines a new definition with an existing one. Named patterns are global to a grammar and can be referenced by ref in the scope of their grammar and by parentRef in the scope of the grammars directly embedded in their grammar.

When define is embedded in include, the new definition is a redefinition. It replaces the definitions from the included grammar, unless a combine attribute is specified, in which case, the definitions are combined.

Restrictions

Named patterns are always global and apply only to patterns. It isn't possible to define and make reference to nonpatterns such as class names or datatype parameters.

Example

<define name="born-element">
  <element name="born">
    <text/>
  </element>
</define>
<define name="book-content" combine="interleave">
  <attribute name="id"/>
  <attribute name="available"/>
  <ref name="isbn-element"/>
  <ref name="title-element"/>
  <zeroOrMore>
    <ref name="author-element"/>
  </zeroOrMore>
  <zeroOrMore>
    <ref name="character-element"/>
  </zeroOrMore>
</define>
  
<define name="isbn-element" combine="choice">
  <notAllowed/>
</define>

Attributes

combine

This attribute specifies how multiple definitions of a named pattern should be combined. The possible values are choice and interleave.

When the combine attribute is specified and set to choice, multiple definitions of a named pattern are combined in a choice pattern. When the combine attribute is specified and set to interleave, multiple definitions of a named pattern are combined in an interleave pattern.

Note that it's forbidden to specify more than one define with the same name and no combine attribute or multiple defines with different values of the combine attribute.

datatypeLibrary

This attribute defines the default datatype library. The value is inherited.

name

This attribute specifies the name of the named pattern.

ns

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


This text is released under the Free Software Foundation GFDL.