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>
 <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, 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!

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.218.15.205