W3C home > Mailing lists > Public > xmlschema-dev@w3.org > October 2012

Re: Order indicators in the .xsd file

From: G. Ken Holman <gkholman@CraneSoftwrights.com>
Date: Wed, 17 Oct 2012 16:18:24 +0200
Message-Id: <>
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) &lt; 4 and count(b) > 1 and count(b) 
&lt; 4 and
      count(c) > 1 and count(c) &lt; 4 and count(d) = 1 and count(e) = 1 and
      count(f) = 1 and count(g) = 1 and count(h) &lt; 2 and count(i) &lt; 2 and
      count(j) &lt; 2 and count(k) &lt; 2 and count(l) &lt; 2 and
      count(m) &lt; 2 and count(n) &lt; 2 and count(o) &lt; 2 and
      count(p) &lt; 2 and count(q) &lt; 2 and count(r) &lt; 2 and
      count(s) &lt; 2 and count(t) &lt; 2 and count(u) &lt; 2 and
      count(v) &lt; 2 and count(w) &lt; 2"/>

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

This archive was generated by hypermail 2.4.0 : Friday, 17 January 2020 23:16:02 UTC