Mixed Content Models with Order

You have seen that a pattern interleaved with a group is allowed to appear anywhere between the patterns of the group. This feature may be used with a text pattern to define ordered mixed-content models, in which the text nodes may appear anywhere but the order of the elements is fixed. These content models are quite unusual in XML. A use case might be a data-oriented vocabulary such as our library, in which optional text can be inserted to provide more user-friendly documentation:

<character id="Lucy">
 <name>Lucy</name> made her first apparition in a Peanuts strip on
 <born>1952-03-03</born>, and the least we can say about her is that she is
 <qualification>bossy, crabby and selfish</qualification>.
</character>

If you want to fix the order of the child elements, just embed a group pattern inside a mixed pattern:

<!--This schema is INVALID-->
<element name="character">
  <mixed>
   <attribute name="id"/>
   <group>
     <element name="name">
       <text/>
     </element>
     <element name="born">
       <text/>
     </element>
     <element name="qualification">
      <text/>
     </element>
    </group>
   </mixed>
  </element>

Per the definition of the mixed pattern, this is equivalent to:

#This schema is invalid
<element name="character">
 <interleave>
  <attribute name="id"/>
  <text/>
  <group>
   <element name="name">
     <text/>
   </element>
   <element name="born">
     <text/>
   </element>
   <element name="qualification">
    <text/>
   </element>
  </group>
 </interleave>
</element>

The text pattern matches text nodes before, after, or between the ...

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.