Hi there,
I'm trying to define a relaxNG schema for a rather complicated document and I'm
getting confused. Basically, I'm not sure how to interleave elements outside of
a group. I have a feeling I may be doing it wrong -- that is, trying to define
a schema that shouldn't be defined, but I'm not sure what the best solution is.
Basically, I want a single schema that supports multiple documents, something
like this:
<payment>
<type>Cash</type>
<amount>42.42</amount>
</payment>
or this (ie: order doesn't matter)
<payment>
<amount>42.42</amount>
<type>Cash</type>
</payment>
Or this (when using credit card, the card_data element is required):
<payment>
<type>Credit Card</type>
<amount>42.42</amount>
<card_data>
<!-- subelements for card number, name, etc -->
</card_data>
</payment>
Or this (order still doesn't matter):
<payment>
<card_data>
<!-- subelements for card number, name, etc -->
</card_data>
<amount>42.42</amount>
<type>Credit Card</type>
</payment>
but not this (card_data should not be supplied when type is cash:
<payment>
<type>Cash</type>
<amount>42.42</amount>
<card_data>
<!-- subelements for card number, name, etc -->
</card_data>
</payment>
This is the closest rng schema I've got so far:
<element name="payment">
<interleave>
<choice>
<element name="type"><value>Cash</value><element>
<group>
<element name="type"><value>Credit Card</value><element>
<element name="card_data">
<!-- subelement definition -->
</element>
</group>
</choice>
<element name="amount"><text /></element>
</interleave>
</element>
The problem is that I think this requires the group containing type and
card_data to be in order; I don't know how to interleave these elements with
the outer amount element so that any ordering can be allowed.
My actual schema is quite a bit more complicated, but this basic problem of
'allow any ordering' is all that is keeping me from completely defining it. I
actually also want to 'allow any ordering' in any subelement structures as
well, so if there is schema-global way to do this, it would solve my problem as
well.
If there isn't a solution, does this mean I'm designing a stupid schema and
should be looking at a smarter layout?
Thanks,
Dusty