Saturday, March 14, 2015

optional settings in XSDs

If Foo and Bar are mandatory here...

<xs:sequence>
   <xs:element name="Foo" type="xs:string" />
   <xs:element name="Bar" type="xs:decimal" />
</xs:sequence>

 
 

...then herein there is a switch up in which one may either use Bar or Baz and one must specify one or the other.

<xs:sequence>
   <xs:element name="Foo" type="xs:string" />
   <xs:choice>
      <xs:element name="Bar" type="xs:decimal" />
      <xs:element name="Baz" type="xs:string" />
   </xs:choice>
</xs:sequence>

 
 

 
 

Here, Bar is back to being a must-have and Baz is optional standalone.

<xs:sequence>
   <xs:element name="Foo" type="xs:string" />
   <xs:element name="Bar" type="xs:decimal" />
   <xs:element name="Baz" type="xs:string" minOccurs="0" />
</xs:sequence>

No comments:

Post a Comment