Expanding the form-letter example, a sequence adds support for
various letter components to the formletter.xsd
schema:
<xs:element name="letter">
<xs:complexType mixed="true">
<xs:sequence>
<xs:element name="greeting"/>
<xs:element name="body"/>
<xs:element name="closing"/>
</xs:sequence>
</xs:complexType>
</xs:element>
Now, thanks to the xs:sequence element, a letter
must include a greeting element, a
body element, and a closing
element, in that order. But in some cases, what is desired is that
one and only one element appear from a collection of possibilities.
The xs:choice element supports this. For example,
if the greeting element needed to be restricted to
contain only one salutation out of a permissible list, it could be
declared to do so using xs:choice:
<xs:element name="greeting">
<xs:complexType mixed="true">
<xs:choice>
<xs:element name="hello"/>
<xs:element name="hi"/>
<xs:element name="dear"/>
</xs:choice>
</xs:complexType>
</xs:element>
Now one of the permitted salutations must appear in the
greeting element for the letter to be considered
valid.
The remaining element-order enforcement construct is the
xs:all element. Unlike the
xs:sequence and xs:choice
elements, the xs:all element must appear at the
top of the content model and can only contain elements that are
optional or appear only once. The xs:all construct
tells the schema processor that each of the contained elements must
appear once in the target document, but can appear in any order. This
could be applied in the form-letter example. If the form letter had
certain elements that had to appear in the body
element, but not in any particular order, xs:all
could be used to control their appearance:
<xs:element name="body">
<xs:complexType mixed="true">
<xs:all>
<xs:element name="item"/>
<xs:element name="price"/>
<xs:element name="arrivalDate"/>
</xs:all>
</xs:complexType>
</xs:element>