1

I have schema where I want either of element is mandatory and they should not repeat.

EDITED -- Here valid request can contain both query and id in request or with only query or id element is also valid. e.g:

 <soapenv:Body>
      <ws:SomeOperation>
         <SoapOperation>
            <query>test</query>
            <id>1</id>
         </SoapOperation>
      </ws:SomeOperation>
 </soapenv:Body>

Valid Requests:

  1. with query and id element.
  2. with only query element.
  3. with only id element.

Invalid Requests:

  1. without query and id element.
  2. with multiple query element.
  3. with multiple id element.

I want query or id must be present. One of them is mandatory. I tried below things:

<xs:sequence>
                   <xs:element  minOccurs="0" name="id">
                        <xs:simpleType>
                            <xs:restriction base="xs:string">
                                <xs:minLength value="1" />
                            </xs:restriction>
                        </xs:simpleType>
                    </xs:element>
                    <xs:element  minOccurs="0" name="query">
                        <xs:simpleType>
                            <xs:restriction base="xs:string">
                                <xs:minLength value="1" />
                            </xs:restriction>
                        </xs:simpleType>
                    </xs:element>   
</xs:sequence>

Here the problem is none of them is mandatory and making any one as minoccurs=1 will make that field mandatory ( e.g. if i mark id as minoccurs=1 then id field is mandatory but my valid request can have only query and not id) and there can be possibility of both tags to be present as well.

Also I tried choice tag.

Using simple choice with will make these tags repeat which also i do not want. The tag should not repeat.

MAY
  • 135
  • 11
  • 1
    Why didn't `xs:choice` work? It doesn't have to allow repeating; it'll naturally handle your need for ***either*** `query` ***or*** `id`, once, and not both. – kjhughes Jan 25 '16 at 12:32
  • I agree; if you set minOccurs to 1 on both elements within the xs:choice then the validator will not allow an empty choice group. It will insist that the choice contains *something*. Which is what you want, I think. – kimbert Jan 25 '16 at 17:02
  • Thanks for the reply. I edited the question to provide more example. Hope this will make clear the doubt i had. – MAY Jan 27 '16 at 11:07

0 Answers0