complexType mixed="true" and choice : choice « XML Schema « XML






complexType mixed="true" and choice


File: Data.xml
<?xml version="1.0" standalone="yes"?>
<Recipe xmlns:xsi="http://www.w3.org/2001/10/XMLSchema-instance">
  <title>title</title>
  <Body>
    text
    <ingredient>inner</ingredient>
    test
    <ingredient>inner</ingredient>
    after
  </Body>
</Recipe>


File: Schema.xsd
<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
  elementFormDefault="qualified">
  <xsd:element name="Recipe">
    <xsd:complexType>
      <xsd:sequence>
        <xsd:element ref="title" />
        <xsd:element ref="Body" />
      </xsd:sequence>
    </xsd:complexType>
  </xsd:element>
  <xsd:element name="title" type="xsd:string">
  </xsd:element>
  <xsd:element name="Body">
    <xsd:complexType mixed="true">
      <xsd:choice>
        <xsd:element ref="ingredient" minOccurs="0"
          maxOccurs="unbounded" />
      </xsd:choice>
    </xsd:complexType>
  </xsd:element>
  <xsd:element name="ingredient" type="xsd:string">
  </xsd:element>
</xsd:schema>

 








Related examples in the same category

1.choice minOccurs="0" maxOccurs="unbounded"
2.Choice with three elements
3.Use choice to define elements with random number and occurence