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.


Mixed content models with order

We have seen that an 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, where 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 could be inserted to provide more user friendly document such as:

   <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 we want to fix the order of the child elements, we can just embed a group pattern inside a mixed pattern:

     <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:

     <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 elements of the group, but as we've seen with our museum example in the previous section, the order of the elements in the group will still be enforced. The compact syntax will use the mixed pattern with commas (,) between sub-patterns to express this:

   element character {
    mixed {
     attribute id {text},
     element name {text},
     element born {text},
     element qualification {text}
    }
   }

We have already seen that the compact syntax mixed pattern can be used using ampersands (&) and commas (,) to define unordered and ordered mixed patterns. An "or" (|) can also be used to interleave text nodes in choice patterns:

 element foo{
  mixed {
   (
    element in1.1 {empty},
    element in1.2 {empty}
   ) | (
    element in2.1 {empty}&
    element in2.2 {empty}
   )
  }
 }

This mixed pattern is interleaving text nodes into either a group (denoted by a comma) of in1.1 and in1.2 elements or (|)an interleave pattern (denoted by an ampersand) of elements in2.1 and in2.2. In the first case because of the semantic of group patterns, the order between elements is fixed while in the second case, the order doesn't matter. Mixed choice contents do not constitute new content models. They are equivalent to choices of mixed content models: we could rewrite this schema as:

 element foo{
  (
   mixed{
    element in1.1 {empty},
    element in1.2 {empty}
    }
  ) | (
   mixed{
    element in2.1 {empty}&
    element in2.2 {empty}
   }
  )
 }
 }

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.