You can further express occurrence behavior by using the minOccurs and maxOccurs attributes with either the choice element or the element declarations themselves. : choice « XML Schema « XML Tutorial






<xsd:element name="middleName">
  <xsd:complexType>
   <xsd:choice maxOccurs="2">
    <xsd:element name="initial" type="xsd:string"/>
    <xsd:element name="name" type="xsd:string"/>
   </xsd:choice>
  </xsd:complexType>
</xsd:element>

The middleName element to contain one of two child elements: initial or name

<middleName>
  <initial>S</initial>
</middleName>
<middleName>
  <name>Stolte</name>
</middleName>

To allow for this content model, we would have to use the choice element:

<xsd:element name="middleName">
  <xsd:complexType>
   <xsd:choice>
    <xsd:element name="initial" type="xsd:string"/>
    <xsd:element name="name" type="xsd:string"/>
   </xsd:choice>
  </xsd:complexType>
</xsd:element>








3.58.choice
3.58.1.Creating a Set of Choices
3.58.2. Declarations
3.58.3.Allow the document instance author to use the initial element twice
3.58.4.You can further express occurrence behavior by using the minOccurs and maxOccurs attributes with either the choice element or the element declarations themselves.