Gordon
Gordon

Reputation: 317119

Change Sequence to Choice

In my Schema File I defined a Group with a Sequence of possible Elements.

<group name="argumentGroup">
    <sequence>
        <element name="foo" type="double" />
        <element name="bar" type="string" />
        <element name="baz" type="integer" />
    </sequence> 
</group>

I then reference this Group like this:

<element name="arguments">
    <complexType>
        <group ref="my:argumentGroup"/>
    </complexType>
</element>

Is it possible to reference the Group at some other point but restrict it so it's a Choice instead of a Sequence. The position where I want to reuse it would only allow one of the Elements within.

<element name="argument" minOccurs="0" maxOccurs="1">
    <complexType>
        <group name="my:argumentGroup">
            <! -- Somehow change argumentGroup sequence to choice here -->
        </group>
    <complexType>
</element>

Upvotes: 2

Views: 301

Answers (2)

pmartin
pmartin

Reputation: 2741

No. You cannot do this with groups. To get this type of reusability, use a complex type instead of a group to define the sequence of elements (foo, bar, baz).

Assign this complex type to an element in your schema using restriction. However, you would need the base complex type to use the choice element.

It seems that, using restriction, you can update the choice element to be a sequence in the restriction. However, if the base complex type is defined using a sequence, then updating the restricted element to a choice will cause the schema to fail validation.

Upvotes: 2

Michael Kay
Michael Kay

Reputation: 163458

No, you will need to define a different group.

Upvotes: 5

Related Questions