Re: mixing childs in any order and any quantity

At 2006-10-06 11:54 +0200, Fermín Galán Márquez wrote:
>I'm trying to define using XML Schema a element which content mixes several
>elements, some of then multiple, that can come in any order and I wonder if
>even this is possible.

Not in W3C Schema.  This concept is called "interleave" in RELAX-NG.

I gather this same issue arises with the content 
of the HTML <head> element where a number of 
elements can be interleaved, and some elements 
have a restriction on their cardinality.

>Let me clarify with a example. Consider a <book> element whose content can
>be up to one <title> (minOccurs=0, maxOccurs=1), up to one <author>
>(minOccurs=0, maxOccurs=1) and many <chapter> (minOccurs=0,
>maxOccurs=unbounded) that comes together, but combining child tags in any
>order.
>
>Examples:
>
><book>
>    <title>...</title>
>    <chapter>...</chapter>
>    <chapter>...</chapter>
>    <chapter>...</chapter>
>    <author>...</autor>
></book>
>
><book>
>    <title>...</title>
>    <author>...</autor>
>    <chapter>...</chapter>
>    <chapter>...</chapter>
>    <chapter>...</chapter>
></book>
>
>How would be the XML Schema definition for such <book> element, please?

As I see it, you are obliged to make the effort 
to enumerate the combinations in a fashion that 
is not ambiguous.  For your above example, the 
following shorthand notation would describe the content of book:

  title, ( ( chapter+, author ) | ( author, chapter+ ) )

>Firstly, I though using <xs:all>, but the problem is that it only allows
>elements with maxOccurs=1, so it doesn't fit with <chapter> (that has
>maxOccurs=unbounded).
>
>Anybody knows a solution or workaround, please? I'm getting crazy reviewing
>the XML Schema reference for some solution, but I'm not finding anything ..

I don't believe you will find precisely what you 
are looking for (and I would welcome being 
corrected on this!) ... I think you have to 
enumerate the possibilities yourself.

I hope this helps.

. . . . . . . . . . . . Ken

--
UBL/XSLT/XSL-FO training: Allerød/Vårø Denmark 2006-11-13,17,20/24
UBL International 2006  2006-11-13/17 http://www.ublconference.com
World-wide corporate, govt. & user group UBL, XSL, & XML training.
G. Ken Holman                 mailto:gkholman@CraneSoftwrights.com
Crane Softwrights Ltd.          http://www.CraneSoftwrights.com/x/
Box 266, Kars, Ontario CANADA K0A-2E0    +1(613)489-0999 (F:-0995)
Male Cancer Awareness Aug'05  http://www.CraneSoftwrights.com/x/bc
Legal business disclaimers:  http://www.CraneSoftwrights.com/legal

Received on Friday, 6 October 2006 14:18:54 UTC