- From: Jeni Tennison <jeni@jenitennison.com>
- Date: Mon, 23 Aug 2004 14:17:35 +0100
- To: "Asleson, Ryan" <asleson@BIWORLDWIDE.com>
- CC: "'xmlschema-dev@w3.org'" <xmlschema-dev@w3.org>
Hi Ryan,
> How can I specify this in the XML schema? According to the
> documentation I've seen, the complexType tag must use an occurrence
> indicator of all, choice, or sequence. All might work, since order
> doesn't matter, but apparently it specifies that each child element
> can occur once and only once once, which doesn't work. Choice
> doesn't work because only one of the elements can appear. Sequence
> might work because it allows me to specify multiple occurrences of
> child elements, but it enforces the order of the child elements,
> which I don't want.
>
> How can I specify this complex type in the XML schema? I'm sure it
> can be done, I'm just not sure how.
This is the most frequent of FAQs. It can't be done in XML Schema.
Your options are:
1. Constrain the order as in your current schema, and use a simple
transformation to transform the any-order documents into the
constrained-order documents, which you can then validate.
2. Use a content model with no constraints on occurrence, as in:
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:element ref="father" />
<xs:element ref="mother" />
<xs:element ref="son" />
<xs:element ref="daughter" />
<xs:element ref="pet" />
</xs:choice>
and add supplementary Schematron rules to constrain the occurrence of
each of the elements. The Schematron rules can be processed in a
separate step.
3. Switch to using RELAX NG, where you can do:
<interleave>
<optional><ref name="father" /></optional>
<optional><ref name="mother" /></optional>
<zeroOrMore><ref name="son" /></zeroOrMore>
<zeroOrMore><ref name="daughter" /></zeroOrMore>
<zeroOrMore><ref name="pet" /></zeroOrMore>
</interleave>
or, in compact syntax:
father? & mother? & son* & daughter* & pet*
Cheers,
Jeni
---
Jeni Tennison
http://www.jenitennison.com/
Received on Monday, 23 August 2004 13:17:49 UTC