RELAX NG by Eric van der Vlist will be published by O'Reilly & Associates (ISBN: 0596004214)

You are welcome to use our annotation system to give your feedback.


The interleave pattern

The second compositor we'll talk about, interleave, describes a set of unordered patterns--a set of patterns which will be considered valid when they match the content of the instance documents in any order.

[Note]Note

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 is the same than the algorithm to validate any node in interleave compositors. Of course, the validation of interleave patterns does not mean that the order of elements and text nodes in the instance document will not be reported to the application; only that they are allowed to appear in any order.

To specify that character elements may accept children elements in any order, we 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 a ampersand ("&") character as a separator instead of the 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 children elements appear in any order:

   <character id="PP">
    <name>Peppermint Patty</name>
    <born>1966-08-22</born>
    <qualification>bold, brash and tomboyish</qualification>
    </character>
   <character id="Snoopy">
    <born>1950-10-04</born>
    <qualification>extroverted beagle</qualification>
    <name>Snoopy</name>
   </character>
   <character id="Schroeder">
    <qualification>brought classical music to the Peanuts strip</qualification>
    <name>Schroeder</name>
    <born>1951-05-30</born>
   </character>

Although interleave looks straightforward at this point, we will 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!


You are welcome to use our annotation system to give your feedback.
[Annotations for this page]
All text is copyright Eric van der Vlist, Dyomedea. During development, I give permission for non-commercial copying for educational and review purposes. After publication, all text will be released under the Free Software Foundation GFDL.