- From: G. Ken Holman <gkholman@CraneSoftwrights.com>
- Date: Wed, 17 Oct 2012 16:18:24 +0200
- To: xmlschema-dev@w3.org
At 2012-10-16 15:13 -0700, Fred Li wrote:
>Hi XML experts,
>
>I have a problem about the use of order indicators in the creation of
>XML schema (.xsd file). As I learned from W3School
>(http://www.w3schools.com/schema/schema_complex_indicators.asp), we
>have 3 order indicators in the XML Schema language:
>
>All - the child elements can appear in any order, and each child
>element must occur only once
>Choice - either one child element or another can occur
>Sequence - the child elements must appear in a specific order
>
>I have an element (for example <asset>) that has 23 child elements,
>three of them can have more than 1 instances, and 7 of them are
>required (includes the 3 have more than 1 instances). According to the
>definition of the order indicators, "sequence" is the only indicator I
>can use in the XML schema, but I hope there is no order restriction
>for the appearance of 23 child elements. Do you have any ideas to
>solve this problem?
Theoretically, you could choose to express every possible permutation
in a big choice, but it would be untenable to develop and to
maintain. I think in W3C Schema 1.0 this is the only way.
Using W3C Schema 1.1 I think you could just allow any number of all
of them and then assert the cardinality of the ones that have restrictions:
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:element ref="a"/>
<xs:element ref="b"/>
<xs:element ref="c"/>
<xs:element ref="d"/>
<xs:element ref="e"/>
<xs:element ref="f"/>
<xs:element ref="g"/>
<xs:element ref="h"/>
<xs:element ref="i"/>
<xs:element ref="j"/>
<xs:element ref="k"/>
<xs:element ref="l"/>
<xs:element ref="m"/>
<xs:element ref="n"/>
<xs:element ref="o"/>
<xs:element ref="p"/>
<xs:element ref="q"/>
<xs:element ref="r"/>
<xs:element ref="s"/>
<xs:element ref="t"/>
<xs:element ref="u"/>
<xs:element ref="v"/>
<xs:element ref="w"/>
<xs:assert test="
count(a) > 1 and count(a) < 4 and count(b) > 1 and count(b)
< 4 and
count(c) > 1 and count(c) < 4 and count(d) = 1 and count(e) = 1 and
count(f) = 1 and count(g) = 1 and count(h) < 2 and count(i) < 2 and
count(j) < 2 and count(k) < 2 and count(l) < 2 and
count(m) < 2 and count(n) < 2 and count(o) < 2 and
count(p) < 2 and count(q) < 2 and count(r) < 2 and
count(s) < 2 and count(t) < 2 and count(u) < 2 and
count(v) < 2 and count(w) < 2"/>
</xs:choice>
An alternative answer is not to use W3C Schema and to use the
"interleave" modeling semantic in ISO/IEC 19757-2 RELAX-NG where you
can express the following in the compact syntax:
( a & a? & a? & b & b? & b? & c & c? & c? & d & e & f & g & h? &
i? & j? & k? & l? & m? & n? & o? & p? & q? & r? & s? & t? & u? & v? & w? )
You can see that the end result requires one of a through g (the 7
required constructs), up to 3 of each of a, b and c, and the rest are
all optional. The
interleave allows them to show up in any order at all.
I hope this helps.
. . . . . . . . . Ken
--
Contact us for world-wide XML consulting and instructor-led training
Free 5-hour lecture: http://www.CraneSoftwrights.com/links/udemy.htm
Crane Softwrights Ltd. http://www.CraneSoftwrights.com/x/
G. Ken Holman mailto:gkholman@CraneSoftwrights.com
Google+ profile: https://plus.google.com/116832879756988317389/about
Legal business disclaimers: http://www.CraneSoftwrights.com/legal
Received on Wednesday, 17 October 2012 14:25:37 UTC