xml-general mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Baptiste Burgaud" <...@teamlog.fr>
Subject Re: Schema - conjunction question
Date Thu, 09 Aug 2001 10:02:08 GMT
Hi John,

> I have a question reqarding the order imposed on elements in a schema.

I think you will get more answers on xmlschema-dev@w3.org

> The document "XML Schema Part 1: Structures, W3C Recommendation 2 May
> 2001" says that a model group may be one of three types as follows:
>
> "2.2.3.1 Model Group
>
> A model group is a constraint in the form of a grammar fragment that
> applies to lists of element information items. It consists of a list of
> particles, i.e. element
> declarations, wildcards and model groups. There are three varieties of
> model group:
>
>      Sequence (the element information items match the particles in
> sequential order);
>      Conjunction (the element information items match the particles, in
> any order);
>      Disjunction (the element information items match one of the
> particles)."
>
> I think I want a "Conjunction" (instead of a sequence) but I can't seem
> to find an appropriate example of  how to construct such a conjunction.
> Can anyone point me to some material which addresses this variation?
>

you should use the <all> compositor, as said in the "XML Schema Part 1:
Structures" document :

"3.8.1 The Model Group Schema Component
The model group schema component has the following properties:

Schema Component: Model Group
{compositor}
One of all, choice or sequence.
{particles}
A list of particles
{annotation}
Optional. An annotation.
specifies a sequential (sequence), disjunctive (choice) or conjunctive (all)
interpretation of the {particles}. This in turn determines whether the
element information item [children] ·validated· by the model group must:

(sequence) correspond, in order, to the specified {particles};
(choice) corresponded to exactly one of the specified {particles};
(all) contain all and only exactly zero or one of each element specified in
{particles}. The elements can occur in any order. In this case, to reduce
implementation complexity, {particles} is restricted to contain local and
top-level element declarations only, with {min occurs}=0 or 1, {max
occurs}=1. "

"Example
<xs:all>
 <xs:element ref="cats"/>
 <xs:element ref="dogs"/>
</xs:all>"

> I am trying to define a complexType which may have its elements in any
> order with the usual range of constraints on each element. Some elements
> may have maxOccurs > 1.

this is more complex, as "{particles} is restricted to contain local and
top-level element declarations only, with {min occurs}=0 or 1, {max
occurs}=1" when using the <all> compositor.

what you can do is:

<xs:group name="myModelGroup1">
    <xs:sequence>
        <xs:element
            minoccurs="0"
            maxoccurs="whateverOccurYouNeed"
            ref="someThing"/>
        <xs:element ref="anotherThing"/>
        <xs:element ref="yetAnotherThing"/>
    </xs:sequence>
</xs:group>

<xs:group name="myModelGroup2">
    <xs:sequence>
        <xs:element
            minoccurs="0"
            maxoccurs="whateverOccurYouNeed"
            ref="someThing"/>
        <xs:element ref="yetAnotherThing"/>
        <xs:element ref="anotherThing"/>
    </xs:sequence>
</xs:group>

<xs:group name="myModelGroup3">
    <xs:sequence>
        <xs:element ref="anotherThing"/>
        <xs:element ref="yetAnotherThing"/>
        <xs:element
            minoccurs="0"
            maxoccurs="whateverOccurYouNeed"
            ref="someThing"/>
    </xs:sequence>
</xs:group>

<xs:group name="myModelGroup4">
    <xs:sequence>
        <xs:element ref="anotherThing"/>
        <xs:element
            minoccurs="0"
            maxoccurs="whateverOccurYouNeed"
            ref="someThing"/>
        <xs:element ref="yetAnotherThing"/>
    </xs:sequence>
</xs:group>

<xs:group name="myModelGroup5">
    <xs:sequence>
        <xs:element ref="yetAnotherThing"/>
        <xs:element ref="anotherThing"/>
        <xs:element
            minoccurs="0"
            maxoccurs="whateverOccurYouNeed"
            ref="someThing"/>
    </xs:sequence>
</xs:group>

<xs:group name="myModelGroup6">
    <xs:sequence>
        <xs:element ref="yetAnotherThing"/>
        <xs:element
            minoccurs="0"
            maxoccurs="whateverOccurYouNeed"
            ref="someThing"/>
        <xs:element ref="anotherThing"/>
    </xs:sequence>
</xs:group>

<xs:complexType name="myComplexType">
    <xs:choice>
        <xs:group ref="myModelGroup1"/>
        <xs:group ref="myModelGroup2"/>
        <xs:group ref="myModelGroup3"/>
        <xs:group ref="myModelGroup4"/>
        <xs:group ref="myModelGroup5"/>
        <xs:group ref="myModelGroup6"/>
    </xs:choice>
</xs:complexType>

this will end with the regular expr you want (where someThing element is
"s", anotherThing element is "a" and yetAnotherThing element is "y")  :
( sa*y | sya* | a*ys | a*sy | ya*s | ysa* )
where the multiple element is bounded to "whateverOccurYouNeed"

Well, I hope someone has a better solution, because this one force to define
!n groups... (n is the number of different elements)




---------------------------------------------------------------------
In case of troubles, e-mail:     webmaster@xml.apache.org
To unsubscribe, e-mail:          general-unsubscribe@xml.apache.org
For additional commands, e-mail: general-help@xml.apache.org


Mime
View raw message