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

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.


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">
  <attribute name="id"/>
  <element name="name">
  <element name="born">
  <element name="qualification">

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>
 <qualification>bold, brash and tomboyish</qualification>
<character id="Snoopy">
 <qualification>extroverted beagle</qualification>
<character id="Schroeder">
 <qualification>brought classical music to the Peanuts strip</qualification>

Although interleave looks straightforward at this point, you'll see that it has more complicated behavior and restrictions. In the last sections of this chapter, we'll look at some of the complexities. You can skip them if they look overwhelming right now, but please remember to come back and revisit them, especially if your interleave patterns produce unexpected results or error messages!

This text is released under the Free Software Foundation GFDL.