1

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>
cafce25
  • 15,907
  • 4
  • 25
  • 31
Axel Jonsson
  • 37
  • 2
  • 7
  • I would like to add that I tried nesting the "row" element in a sequence by its own, so that the choice tags would containt two sequences. But it didn't make a difference. – Axel Jonsson Mar 07 '16 at 14:46
  • Yes it's doable. Your complexType looks ok can you show us more of your schema and a sample XML to be validated against this schema. Thanks. – potame Mar 07 '16 at 14:52
  • I don't currently have an XML to validate against. I updated my original post as to where I'm currently at, I hope it helps. – Axel Jonsson Mar 07 '16 at 15:00
  • An xs:complexType element as a child of xs:choice is incorrect, and your schema processor should complain loudly about it. – Michael Kay Mar 07 '16 at 16:16
  • 2
    Where you say "current output" what exactly is this the output of? You haven't said what processing you are doing - only that you don't have an instance XML document available. Perhaps this is the output of some tool that generates sample instances that match your schema? In that case it's taking an incorrect schema and producing an incorrect instance from it - find a better tool. – Michael Kay Mar 07 '16 at 16:19
  • Sorry, I wrote it in a comment below Nikolas answer. I solved it now however, and I'll post the answer! Thanks for your help! – Axel Jonsson Mar 08 '16 at 07:34

1 Answers1

2

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>
Nikolas Charalambidis
  • 40,893
  • 16
  • 117
  • 183
  • I'm still getting the same output. I'm using soapUI and loading a "request template" i suppose, from WDSL. I don't think that the current output (in my original post) gives sufficient instructions, e.g either path AND filename, or ONLY row. (I'm very new to this, but it's my assignment, so sorry if I'm not making sense) – Axel Jonsson Mar 07 '16 at 15:20