A Restriction Related to interleave

You’ll see the restrictions of RELAX NG in Chapter 15, but I need to mention the principal restriction related to the interleave compositor, as it might affect you at some point if you combine mixed-content models.

Let’s extend our title element to allow not only links (a elements) but also bold characters marked by a b element:

<title xml:lang="en">Being a
 <a href="http://dmoz.org/Recreation/Pets/Dogs/">Dog</a>
    Is a <b>Full-Time</b>
 <a href="http://dmoz.org/Business/Employment/Job_Search/">Job</a>
</title>

Because text can appear before the a elements, between a and b, and after the b element, you might be tempted to write the following schemas:

<element name="title">
 <interleave>
  <attribute name="xml:lang"/>
  <text/>
  <zeroOrMore>
    <element name="a">
      <attribute name="href"/>
      <text/>
    </element>
  </zeroOrMore>
  <text/>
  <zeroOrMore>
    <element name="b">
      <text/>
    </element>
  </zeroOrMore>
  <text/>
 </interleave>
</element>

or:

element title {
  attribute xml:lang {text}
  & text
  & element a {attribute href {text}, text} *
  & text
  & element b {text} *
  & text
}

Running the Jing validator against this schema raises the following error:

Error at URL "file:/home/vdv/xmlschemata-cvs/books/relaxng/examples/RngMorePatterns/
interleave-restriction2.rnc",
line number 1, column number 2: both operands of "interleave" contain "text"

This error results because there can be only one text pattern in each interleave pattern. You have seen that text patterns match zero or more text nodes, ...

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.