Definitive XML Schema
Priscilla Walmsley (pwalmsley@datypic.com)
ISBN: 0132886723
2nd edition, , Prentice Hall PTR.
Chapter 10: 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
<xs:simpleType name="SizeType"> <xs:union> <xs:simpleType> <xs:restriction base="xs:integer"> <xs:minInclusive value="2"/> <xs:maxInclusive value="18"/> </xs:restriction> </xs:simpleType> <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="SizeType"> <xs:union memberTypes="DressSizeType SMLSizeType"/> </xs:simpleType>
<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="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>
<size xsi:type="DressSizeType">12</size>
<xs:simpleType name="AvailableSizesType"> <xs:list itemType="DressSizeType"/> </xs:simpleType>
<availableSizes>10 12 14</availableSizes>
<xs:simpleType name="AvailableSizesType"> <xs:list> <xs:simpleType> <xs:restriction base="xs:integer"> <xs:minInclusive value="2"/> <xs:maxInclusive value="18"/> </xs:restriction> </xs:simpleType> </xs:list> </xs:simpleType>
<xs:simpleType name="AvailableSizesType"> <xs:restriction> <xs:simpleType> <xs:list itemType="SMLSizeType"/> </xs:simpleType> <xs:maxLength value="3"/> </xs:restriction> </xs:simpleType>
<availableSizes>medium large</availableSizes>
<xs:simpleType name="AvailableSizesType"> <xs:restriction> <xs:simpleType> <xs:list itemType="xs:token"/> </xs:simpleType> <xs:enumeration value="small"/> <xs:enumeration value="medium"/> <xs:enumeration value="large"/> </xs:restriction> </xs:simpleType>
<xs:simpleType name="AvailableSizesType"> <xs:list> <xs:simpleType> <xs:restriction base="xs:token"> <xs:enumeration value="small"/> <xs:enumeration value="medium"/> <xs:enumeration value="large"/> </xs:restriction> </xs:simpleType> </xs:list> </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>
<applicableSizes>small medium large</applicableSizes> <applicableSizes>2 4 6 8 10 12 14 16 18</applicableSizes>
<xs:simpleType name="VectorType"> <xs:restriction> <xs:simpleType> <xs:list itemType="xs:unsignedInt"/> </xs:simpleType> <xs:pattern value="\d+\s+\d+\s+((\d+\s+){3})*\d+"/> </xs:restriction> </xs:simpleType>
<xs:simpleType name="AvailableSizesType"> <xs:list itemType="SMLXSizeType"/> </xs:simpleType> <xs:simpleType name="SMLXSizeType"> <xs:restriction base="xs:token"> <xs:enumeration value="small"/> <xs:enumeration value="medium"/> <xs:enumeration value="large"/> <xs:enumeration value="extra large"/> </xs:restriction> </xs:simpleType>
<availableSizes> small extra large </availableSizes>
<xs:simpleType name="SizeType"> <xs:union memberTypes="DressSizeType SMLXSizeType"/> </xs:simpleType> <xs:simpleType name="AvailableSizesType"> <xs:list itemType="SizeType"/> </xs:simpleType>
<availableSizes>10 large 2</availableSizes>
<xs:simpleType name="RowType"> <xs:list itemType="xs:integer"/> </xs:simpleType> <xs:simpleType name="TwoDimensionalArrayType"> <xs:list itemType="RowType"/> </xs:simpleType>
<xs:complexType name="VectorType"> <xs:sequence maxOccurs="unbounded"> <xs:element name="e" type="xs:integer"/> </xs:sequence> </xs:complexType> <xs:complexType name="ArrayType"> <xs:sequence maxOccurs="unbounded"> <xs:element name="r" type="VectorType"/> </xs:sequence> </xs:complexType> <xs: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>