Using External References
External references
offer a powerful but simple mechanism for including a pattern
contained in an external document at any location in a schema. This
feature works through raw inclusion of the referenced external
document. The externalRef
pattern is replaced by
the content of the document. That document may be a complete RELAX NG
schema, though that isn’t required, but a valid
pattern is required.
With Russian Doll Schemas
You
may want to reuse existing
schemas as a whole, without modifying any of their definitions.
Imagine, for instance, that we have defined two grammars in two
schemas to describe our author
and
character
elements. First, create a RELAX NG
schema, author.rng, to describe our authors:
<?xml version="1.0" encoding="UTF-8"?> <element name="author" xmlns="http://relaxng.org/ns/structure/1.0" datatypeLibrary="http://www.w3.org/2001/XMLSchema-datatypes"> <attribute name="id"> <data type="ID"/> </attribute> <element name="name"> <data type="token" datatypeLibrary=""/> </element> <optional> <element name="born"> <data type="date"/> </element> </optional> <optional> <element name="died"> <data type="date"/> </element> </optional> </element>
or, in the compact syntax, author.rnc:
element author { attribute id { xsd:ID }, element name { token }, element born { xsd:date }?, element died { xsd:date }? }
Then create a second schema, character.rng, to describe our characters:
<?xml version="1.0" encoding="UTF-8"?> <element name="character" xmlns="http://relaxng.org/ns/structure/1.0" ...
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.