[relaxng-user] A question on content models
James Clark
jjc at jclark.com
Wed Sep 24 15:42:31 ICT 2003
Murata-san has mostly covered this already but since I had my reply
mostly written already I'll send it as well.
> What's the difference between empty and
> notAllowed in this context?
The following analogy may help (or it may just confuse things!): if you
think of choice as addition and interleave as multiplication, then
notAllowed is like 0 and empty is like 1.
Whether to use notAllowed or empty in this context depends on whether
you are going to use combine="choice" or combine="interleave". If
combine="choice" then use notAllowed; if combine="interleave" then use
empty. That's because X | notAllowed is equivalent to X for any pattern
X; similarly, X & empty is equivalent to X for any pattern X.
>>>Individual files usually say something like
>>> <define combine="choice" name="class.reader">
>>> <element name="switch">
>>> <!-- CM -->
>>> </element>
>>> </define>
>>
>>Then use combine="interleave" instead of combine="choice".
>
>
> For attributes or in general? Again, this may be a FAQ, what's the
> difference between "choice" and "interleave" in this context? Is
>
> <define name="a" combine="interleave">
> <!-- -->
> </define>
>
> the same as
>
> <oneOrMore>
> <define name="a" combine="choice">
> <!-- -->
> </define>
> </oneOrMore>
No. The combine attribute just says what happens when you have two
definitions with the same name. My fingers are getting tired, so I'm
going to use the compact syntax here:
a &= X
a &= Y
is the same as
a = X & Y
Also
a = attribute foo { ... } & attribute bar { ... }
is equivalent to
a = attribute foo { ... }, attribute bar { ... }
(because attribute order is not significant). So if you are defining
sets of attributes you want to use empty and &=. You would use
notAllowed and |= for attributes only if you had a case where you wanted
the schema allowed one of a class of attributes (which is rare).
James
More information about the relaxng-user
mailing list