Next / Previous / Contents / TCC Help System / NM Tech homepage

4. The content patterns

RNC notation is an expression syntax. We will introduce its pieces one by one, but an RNC file is in general rather like a syntax description in BNF (Backus-Naur Form): it follows the rules of a context-free grammar.

Operators have no innate precedence. If you use two different operators in an expression, you must parenthesize part of the expression to force precedence.

text

A pattern that matches text (not containing any tags). For example, this pattern specifies that a horse element can contain only text:

    element horse { text }
p*

The pattern p can occur zero or more times. For example, this schema fragment says that a corral element can contain zero or more horse elements:

    element corral
    { element horse { text }*
    }
p+

The pattern p must occur one or more times. For example:

    element forest {
    { element tree { text }+ }

p?

Pattern p is optional. Example:

    element verification {
      element claim { text },
      element result { text }?
    }

This pattern says that a verification element must contain exactly one claim, optionally followed by a result.

xsd:datatype

Specifies a predefined data type defined in XML Schema Part 2: Datatypes. For a list of these datatypes, see Section 6, “The xsd: datatypes”.

For example, this pattern specifies a head-count element whose content must be an integer greater than zero:

    element head-count { xsd:positiveInteger }

p | q

A pattern that matches either p or q. For example:

    element vehicle {
      attribute vkind { "car" | "bus" | "truck" } ... }

This allows only three valid vkind attributes in a vehicle element: vkind="car", vkind="bus", or vkind="truck".

You can use such an enumeration to restrict the content of elements as well as attributes.

p, q

Matches p followed by q.

p & q

Matches pattern p and pattern q, but those patterns can occur in any order.

For example, this pattern says that a part element must contain exactly one each of the patterns itemName, unitCost, amount, and stockNumber, but they can occur in any order:

    element part { itemName & unitCost & amount & stockNumber }

This kind of pattern is called an interleave.

name |= p

Defines the given named pattern name as o | p, where o is the old content of name.

name &= p

Defines the given named pattern name as o & p, where o is the old content of name.

notAllowed

A special keyword that never matches. You can use this pattern as a placeholder for other content to be added later using the &= or |= operator.

*

In a context where a name is expected, * matches any name.

n1 - n2

If n1 and n2 are name classes, the result is all the names in class n1 except for the names in n2. For example:

    element notes {
      attribute * - (xsl:* | fo:*) { text }*,
      text
    }

This specifies that a notes element can have any attribute name that is not in namespace xsl: or fo:, that the attributes can have any values, and that the notes element's content can be any text.