Axel Jonsson
Axel Jonsson

Reputation: 37

XSD choice between sequence or single element

I'm trying to create a choice between a sequence of two elements, and one single element, as such:

<xs:element name="LoadStationsRequest">
    <xs:choice>

        <xs:complexType>
            <xs:sequence> 
                <xs:element name="path" type="xs:string" />
                <xs:element name="fileName" type="xs:string" />
            </xs:sequence>
        </xs:complexType>

        <xs:complexType>
            <xs:sequence>
                <xs:element name="row" type="xs:string" />
            </xs:sequence>
        </xs:complexType>

    </xs:choice>
</xs:element>

The problem is that the choice tag accepts any of the three elements within it, "path", "fileName" and "row".

What I want is either path AND filename, or ONLY row.

Is this doable? Any clues of how to solve this?

Current output:

<v1:LoadStationsRequest>
    <!--You have a CHOICE of the next 2 items at this level-->
    <v1:path>?</v1:path>
    <v1:fileName>?</v1:fileName>
    <v1:row>?</v1:row>
</v1:LoadStationsRequest>

Upvotes: 1

Views: 2953

Answers (1)

Nikolas
Nikolas

Reputation: 44456

Works for me:

<xs:element name="LoadStationsRequest">
    <xs:complexType>
        <xs:choice>
            <xs:sequence> 
                <xs:element name="path" type="xs:string" />
                <xs:element name="fileName" type="xs:string" />
            </xs:sequence>          
            <xs:sequence>
                <xs:element name="row" type="xs:string" />
            </xs:sequence>
        </xs:choice>
    </xs:complexType>
</xs:element>

Upvotes: 2

Related Questions