by Eric van der Vlist is published by O'Reilly & Associates (ISBN: 0596004214)
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.
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!
This text is released under the Free Software Foundation GFDL.