The interleave Pattern
The second
compositor examined here,
interleave
, describes a set of unordered
patterns—a set of patterns considered valid when they match the
content of the instance documents in any order.
Tip
As far as validation is concerned, this behavior is similar to the
validation of attributes in a
“group” compositor up to the point
that the algorithms to validate attributes within groups are the same
as the algorithm to validate any node in
interleave
compositors. Of course, the validation of
interleave
patterns doesn’t mean
that the order of elements and text nodes in the instance document
aren’t reported to the application, only that they
are allowed to appear in any order.
To specify that character
elements may accept
child elements in any order, you just need to replace our
group
pattern with an
interleave
pattern:
<element name="character"> <interleave> <attribute name="id"/> <element name="name"> <text/> </element> <element name="born"> <text/> </element> <element name="qualification"> <text/> </element> </interleave> </element>
In the compact syntax, interleave
patterns are
marked using an ampersand (&
) character as a
separator instead of a comma, which is the mark of ordered groups:
element character { attribute id {text}& element name {text}& element born {text}& element qualification {text}}
These two equivalent schemas will validate
character
elements when child elements appear in
any order:
<character id="PP"> <name>Peppermint Patty</name> <born>1966-08-22</born> ...
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.