sri
sri

Reputation: 11

XSD schema for unordered mandatory and optional tags

I want to express unordered mandatory and optional tags occurring reccurringly in an XSD. Can any one tell how this problem can be resolved ? If it is not feasible, what is the approach that can be taken.

UPDATE

<xs:element name="Tag1" type="xs:string" />
<xs:element name="Tag2" type="xs:string" />
<xs:element name="Tag3" type="xs:string" maxoccurs="Unbounded"/> 

All these tags appear under a complext type and tag1 and tag2 are mandatory. tag3 is optional and can occur any number of times. tag1, tag2 and tag3 can appear in any order

Upvotes: 1

Views: 161

Answers (1)

tom redfern
tom redfern

Reputation: 31750

You can use a "all" group selector and use minOccurs to indicate mandatory-ness.

<xs:schema xmlns="http://Message1" targetNamespace="http://Message1" xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <xs:element name="Root">
    <xs:complexType>
      <xs:all>
        <xs:element name="TheValue" type="xs:string" />
        <xs:element name="TheValue2" type="xs:string" minOccurs="0" />
      </xs:all>
    </xs:complexType>
  </xs:element>
</xs:schema>

This are correct:

<ns0:Root xmlns:ns0="http://BizTalk_Server_Project1.Message1">
  <TheValue2>somevalue</TheValue2>
  <TheValue>somevalue</TheValue>
</ns0:Root>

and so it this:

<ns0:Root xmlns:ns0="http://BizTalk_Server_Project1.Message1">
  <!--<TheValue2>somevalue</TheValue2>-->
  <TheValue>somevalue</TheValue>
</ns0:Root>

But not this:

<ns0:Root xmlns:ns0="http://BizTalk_Server_Project1.Message1">
  <!--<TheValue2>somevalue</TheValue2>-->
  <!--<TheValue>somevalue</TheValue>-->
</ns0:Root>

Upvotes: 1

Related Questions