<interleave>
problemWhen you begin using Relax NG to describe mixed content, you can come up with this error in your grammar:
<interleave> cannot contain <text/> in more than one branch
Here is what causes this error. Consider a simple weather report that consists of mixed text, with one or more places, low temperatures, and high temperatures.
<report> Here's your weather report. The temperatures for <place>San Jose</place> will be from <low>75</low> to <high>80</high>. <place>San Francisco</place> will have temperatures ranging from <low>55</low> to <high>60</high>. </report>
Here is a correct Relax NG grammar:
<element name="report"> <interleave> <text/> <oneOrMore> <element name="place"> <text/> </element> <element name="low"> <data type="integer"/> </element> <element name="high"> <data type="integer"/> </element> </oneOrMore> </interleave> </element>
However, you might think: “There’s text
between the <place>
, <low>
and <high>
. So shouln’t I write my grammar
this way:” (lines are numbered for reference; line 5 is
the one you added):
1 <element name="report">
2 <interleave>
3 <text/>
4 <oneOrMore>
5 <text/>
6 <element name="place"><text/></element>
7 <element name="low"> <data type="integer"/> </element>
8 <element name="high"> <data type="integer"/> </element>
9 </oneOrMore>
10 </interleave>
11 </element>
No, you can’t. That will generate the error. You can have
only one <text/>
outside an element
between a beginning and ending <interleave>
.
You already have one on line 3; adding the one on line 5 causes
the problem. The <text/>
on line 6 is just fine,
because it is enclosed in an <element>
By the way: the line number in the error message doesn’t give you a clue as to where the error really occurs; you will have to track it down yourself.