Definitive XML Schema
Priscilla Walmsley (pwalmsley@datypic.com)
ISBN: 0130655678
1st edition, , Prentice Hall PTR.
Chapter 11: Union and list types
Full example
This example illustrates union and list types.
<sizes xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="chapter11.xsd"> <size>12</size> <size>medium</size> <smallSize>6</smallSize> <smallSize>small</smallSize> <internationalSize>12</internationalSize> <internationalSize>24</internationalSize> <internationalSize>large</internationalSize> <availableSizes>10 large 2</availableSizes> <applicableSizes>small medium large</applicableSizes> </sizes>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"> <xs:element name="sizes" type="SizesType"/> <xs:complexType name="SizesType"> <xs:choice maxOccurs="unbounded"> <xs:element name="size" type="SizeType"/> <xs:element name="smallSize" type="SmallSizeType"/> <xs:element name="internationalSize" type="InternationalSizeType"/> <xs:element name="availableSizes" type="AvailableSizesType"/> <xs:element name="applicableSizes" type="ApplicableSizesType"/> </xs:choice> </xs:complexType> <xs:simpleType name="SizeType"> <xs:union memberTypes="DressSizeType"> <xs:simpleType> <xs:restriction base="xs:token"> <xs:enumeration value="small"/> <xs:enumeration value="medium"/> <xs:enumeration value="large"/> </xs:restriction> </xs:simpleType> </xs:union> </xs:simpleType> <xs:simpleType name="DressSizeType"> <xs:restriction base="xs:integer"> <xs:minInclusive value="2"/> <xs:maxInclusive value="18"/> </xs:restriction> </xs:simpleType> <xs:simpleType name="SmallSizeType"> <xs:restriction base="SizeType"> <xs:enumeration value="2"/> <xs:enumeration value="4"/> <xs:enumeration value="6"/> <xs:enumeration value="small"/> </xs:restriction> </xs:simpleType> <xs:simpleType name="InternationalSizeType"> <xs:union memberTypes="SizeType"> <xs:simpleType> <xs:restriction base="xs:integer"> <xs:minInclusive value="24"/> <xs:maxInclusive value="54"/> </xs:restriction> </xs:simpleType> </xs:union> </xs:simpleType> <xs:simpleType name="AvailableSizesType"> <xs:list itemType="SizeType"/> </xs:simpleType> <xs:simpleType name="ApplicableSizesType"> <xs:restriction> <xs:simpleType> <xs:list itemType="SizeType"/> </xs:simpleType> <xs:enumeration value="small medium large"/> <xs:enumeration value="2 4 6 8 10 12 14 16 18"/> </xs:restriction> </xs:simpleType> </xs:schema>
Book examples
<xsd:simpleType name="SizeType"> <xsd:union> <xsd:simpleType> <xsd:restriction base="xsd:integer"> <xsd:minInclusive value="2"/> <xsd:maxInclusive value="18"/> </xsd:restriction> </xsd:simpleType> <xsd:simpleType> <xsd:restriction base="xsd:token"> <xsd:enumeration value="small"/> <xsd:enumeration value="medium"/> <xsd:enumeration value="large"/> </xsd:restriction> </xsd:simpleType> </xsd:union> </xsd:simpleType>
<xsd:simpleType name="SizeType"> <xsd:union memberTypes="DressSizeType SMLSizeType"/> </xsd:simpleType>
<xsd:simpleType name="SizeType"> <xsd:union memberTypes="DressSizeType"> <xsd:simpleType> <xsd:restriction base="xsd:token"> <xsd:enumeration value="small"/> <xsd:enumeration value="medium"/> <xsd:enumeration value="large"/> </xsd:restriction> </xsd:simpleType> </xsd:union> </xsd:simpleType>
<xsd:simpleType name="SmallSizeType"> <xsd:restriction base="SizeType"> <xsd:enumeration value="2"/> <xsd:enumeration value="4"/> <xsd:enumeration value="6"/> <xsd:enumeration value="small"/> </xsd:restriction> </xsd:simpleType>
<xsd:simpleType name="InternationalSizeType"> <xsd:union memberTypes="SizeType"> <xsd:simpleType> <xsd:restriction base="xsd:integer"> <xsd:minInclusive value="24"/> <xsd:maxInclusive value="54"/> </xsd:restriction> </xsd:simpleType> </xsd:union> </xsd:simpleType>
<size xsi:type="DressSizeType">12</size>
<xsd:simpleType name="AvailableSizesType"> <xsd:list itemType="DressSizeType"/> </xsd:simpleType>
<availableSizes>10 12 14</availableSizes>
<xsd:simpleType name="AvailableSizesType"> <xsd:list> <xsd:simpleType> <xsd:restriction base="xsd:integer"> <xsd:minInclusive value="2"/> <xsd:maxInclusive value="18"/> </xsd:restriction> </xsd:simpleType> </xsd:list> </xsd:simpleType>
<xsd:simpleType name="AvailableSizesType"> <xsd:restriction> <xsd:simpleType> <xsd:list itemType="SMLSizeType"/> </xsd:simpleType> <xsd:maxLength value="3"/> </xsd:restriction> </xsd:simpleType>
<availableSizes>medium large</availableSizes>
<xsd:simpleType name="AvailableSizesType"> <xsd:restriction> <xsd:simpleType> <xsd:list itemType="xsd:token"/> </xsd:simpleType> <xsd:enumeration value="small"/> <xsd:enumeration value="medium"/> <xsd:enumeration value="large"/> </xsd:restriction> </xsd:simpleType>
<xsd:simpleType name="AvailableSizesType"> <xsd:list> <xsd:simpleType> <xsd:restriction base="xsd:token"> <xsd:enumeration value="small"/> <xsd:enumeration value="medium"/> <xsd:enumeration value="large"/> </xsd:restriction> </xsd:simpleType> </xsd:list> </xsd:simpleType>
<xsd:simpleType name="ApplicableSizesType"> <xsd:restriction> <xsd:simpleType> <xsd:list itemType="SizeType"/> </xsd:simpleType> <xsd:enumeration value="small medium large"/> <xsd:enumeration value="2 4 6 8 10 12 14 16 18"/> </xsd:restriction> </xsd:simpleType>
<applicableSizes>small medium large</applicableSizes> <applicableSizes>2 4 6 8 10 12 14 16 18</applicableSizes>
<xsd:simpleType name="VectorType"> <xsd:restriction> <xsd:simpleType> <xsd:list itemType="xsd:unsignedInt"/> </xsd:simpleType> <xsd:pattern value="((\d+\s*){3})*"/> </xsd:restriction> </xsd:simpleType>
<xsd:simpleType name="AvailableSizesType"> <xsd:list itemType="SMLXSizeType"/> </xsd:simpleType> <xsd:simpleType name="SMLXSizeType"> <xsd:restriction base="xsd:token"> <xsd:enumeration value="small"/> <xsd:enumeration value="medium"/> <xsd:enumeration value="large"/> <xsd:enumeration value="extra large"/> </xsd:restriction> </xsd:simpleType>
<availableSizes> small extra large </availableSizes>
<xsd:simpleType name="SizeType"> <xsd:union memberTypes="DressSizeType SMLXSizeType"/> </xsd:simpleType> <xsd:simpleType name="AvailableSizesType"> <xsd:list itemType="SizeType"/> </xsd:simpleType>
<availableSizes>10 large 2</availableSizes>
<xsd:simpleType name="RowType"> <xsd:list itemType="xsd:integer"/> </xsd:simpleType> <xsd:simpleType name="TwoDimensionalArrayType"> <xsd:list itemType="RowType"/> </xsd:simpleType>
<xsd:complexType name="VectorType"> <xsd:sequence maxOccurs="unbounded"> <xsd:element name="e" type="xsd:integer"/> </xsd:sequence> </xsd:complexType> <xsd:complexType name="ArrayType"> <xsd:sequence maxOccurs="unbounded"> <xsd:element name="r" type="VectorType"/> </xsd:sequence> </xsd:complexType> <xsd:element name="array" type="ArrayType"/>
<array> <r> <e>1</e> <e>12</e> <e>15</e> </r> <r> <e>44</e> <e>2</e> <e>3</e> </r> </array>