Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

XSD choice sequence

Status
Not open for further replies.

amiranda

IS-IT--Management
Feb 2, 2007
3
PT
How can I set a sequence of choices? An example:

<xs:element name="OPERATIONS">
<xs:complexType>
<xs:sequence>
<xs:choice>
<xs:element ref="INSERT"/>
<xs:element ref="UPDATE"/>
<xs:element ref="CREATE"/>
<xs:element ref="DELETE"/>
<xs:element ref="GETLIST"/>
</xs:choice>
</xs:sequence>
</xs:complexType>
</xs:element>

allows me to have one of "INSERT", "UPDATE", etc. But what I want is to have a sequence of "INSERT"s or "UPDATE"s like this:

<OPERATIONS>
<INSERT></INSERT>
<INSERT></INSERT>
<OPERATIONS>


 
Remove the <xs:choice> element

then set the <insert> min ocurring and Max ocurring attributes

eg

Code:
<xs:element name="OPERATIONS">
    <xs:complexType>
        <xs:sequence>
          <xs:element ref="INSERT" minOccurs=0 maxOcurrs=5/>
        </xs:sequence>
    </xs:complexType>
  </xs:element>

will allow between 0 and 5 inserts into the Operations node
 
I know that. But that will allow from 0 to 5 INSERT records. I want to make it possible to have other records (UPDATE, CREATE, etc.) too, but as a choice from one of them. Like:

<OPERATIONS>
<INSERT></INSERT>
<INSERT></INSERT>
<OPERATIONS>

or

<OPERATIONS>
<UPDATE></UPDATE>
<UPDATE></UPDATE>
<OPERATIONS>
 
I solved this problem using:

<xs:element name="OPERATIONS">
<xs:complexType>
<xs:sequence>
<xs:choice>
<xs:element ref="INSERT"/>
<xs:element ref="UPDATE"/>
<xs:element ref="CREATE"/>
<xs:element ref="DELETE"/>
<xs:element ref="GETLIST"/>
</xs:choice>
<xs:element minOccurs="0" maxOccurs="unbounded" ref="INSERT"/>
<xs:element minOccurs="0" maxOccurs="unbounded" ref="UPDATE"/>
<xs:element minOccurs="0" maxOccurs="unbounded" ref="CREATE"/>
<xs:element minOccurs="0" maxOccurs="unbounded" ref="DELETE"/>
<xs:element minOccurs="0" maxOccurs="unbounded" ref="GETLIST"/>
</xs:sequence>
</xs:complexType>
</xs:element>

Probably there is a more elegant whay of doing this, but I think this is working as I wanted! :D
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top