To write an RNC schema, use start construct
to define what content can go into the root element. The
remainder of the schema can be placed inside the start construct, or you can break the schema up
into named parts and use references to those names to
connect the parts of the schema to the start
construct.
namespace
ns
="URI"
Define a namespace prefix
ns using the given URI.
For example:
namespace xsl = "http://www.w3.org/1999/XSL/Transform"
After the above definition, a tag name such as
xsl:comment would match only tags in the
namespace given by that URI.
default namespace =
"URI"
Define the default namespace.
grammar {
definition
... }
The top level of schema definitions. Should include a
start definition.
start =
definition
Declares the content of the root element of the document type.
name =
definition
Names a pattern. You can use such names anywhere a pattern or definition is allowed.
element
name
{ p
}
Specifies that in this document type, the content of
element name must match
p.
An element construct is just
another pattern, which you can nest. For example:
element name {
element first { text },
element last { text }
}
This specifies that a name
element must contain a first
element followed by a last
element.
You can also use the postfix operators *, +, and ? after the
closing brace, for example:
element q-and-a {
element question { text },
element answer { text }*
}
This rule defines the content of a q-and-a element as one question
element followed by zero or more answer elements.
attribute
aname
{ p }
Used inside an element construct to
specify that the element must have an attribute named
aname.
list { p
}
Matches a whitespace-separated list of patterns that
match p.
For example, this pattern would require that a
scores element contain a
space-separated list
scores="i0
f0
i1
f1
…", where each
ik is an integer, and each
fk is a float (type
xsd:double):
attribute scores {
list { (xsd:int, xsd:double)+ }
}mixed {
p }
Matches any mixture of text and
pattern p.
empty
Used to declare that an element has no content. For example:
element newPage { empty }external
"filename"
Matches the RNC patterns defined in file
filename.
include "filename"
Merges with the current grammar the grammar from the named file.
include
"filename"
{
defs
}
Merge the named file into the current grammar,
but replace any definitions from that file with
defs,
the definitions between the braces.
# comment
“#” is the comment
character in RNC. Any characters on a line following
# will be ignored.
## annotation
Lines starting with ## are
special comments that are treated as
annotations to the material
that follows. Some tools may allow you to retrieve
the annotations for a given pattern.