Definitive XML Schema
Priscilla Walmsley (pwalmsley@datypic.com)
ISBN: 0132886723
2nd edition, , Prentice Hall PTR.
Chapter 8: Simple types
Full example
This example illustrates various simple type restrictions using bounds facets, patterns, and enumerations. White space is used in the instance to illustrate that white space processing takes place before validation.
<sizes xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="chapter09.xsd"> <dressSize>06</dressSize> <mediumDressSize>12</mediumDressSize> <smallDressSize>6</smallDressSize> <smlxSize>extra large</smlxSize> <xsmlxSize>extra small</xsmlxSize> </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="dressSize" type="DressSizeType"/> <xs:element name="mediumDressSize" type="MediumDressSizeType"/> <xs:element name="smallDressSize" type="SmallDressSizeType"/> <xs:element name="smlxSize" type="SMLXSizeType"/> <xs:element name="xsmlxSize" type="XSMLXSizeType"/> </xs:choice> </xs:complexType> <xs:simpleType name="DressSizeType"> <xs:restriction base="xs:integer"> <xs:minInclusive value="2"/> <xs:maxInclusive value="18"/> <xs:pattern value="\d{1,2}"/> </xs:restriction> </xs:simpleType> <xs:simpleType name="MediumDressSizeType"> <xs:restriction base="DressSizeType"> <xs:minInclusive value="8"/> <xs:maxInclusive value="12"/> </xs:restriction> </xs:simpleType> <xs:simpleType name="SmallDressSizeType"> <xs:restriction base="DressSizeType"> <xs:minInclusive value="2"/> <xs:maxInclusive value="6"/> <xs:pattern value="\d{1}"/> </xs:restriction> </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> <xs:simpleType name="XSMLXSizeType"> <xs:union memberTypes="SMLXSizeType"> <xs:simpleType> <xs:restriction base="xs:token"> <xs:enumeration value="extra small"/> </xs:restriction> </xs:simpleType> </xs:union> </xs:simpleType> </xs:schema>
Book examples
<xs:simpleType name="DressSizeType"> <xs:restriction base="xs:integer"> <xs:minInclusive value="2"/> <xs:maxInclusive value="18"/> </xs:restriction> </xs:simpleType> <xs:element name="size" type="DressSizeType"/>
<xs:element name="size"> <xs:simpleType> <xs:restriction base="xs:integer"> <xs:minInclusive value="2"/> <xs:maxInclusive value="18"/> </xs:restriction> </xs:simpleType> </xs:element>
<xs:simpleType name="DressSizeType"> <xs:restriction base="xs:integer"> <xs:minInclusive value="2"/> <xs:maxInclusive value="18"/> <xs:pattern value="\d{1,2}"/> </xs:restriction> </xs:simpleType>
<xs:simpleType name="MediumDressSizeType"> <xs:restriction base="DressSizeType"> <xs:minInclusive value="8"/> <xs:maxInclusive value="12"/> </xs:restriction> </xs:simpleType>
<xs:simpleType name="MediumDressSizeType"> <xs:restriction base="xs:integer"> <xs:minInclusive value="8"/> <xs:maxInclusive value="12"/> <xs:pattern value="\d{1,2}"/> </xs:restriction> </xs:simpleType>
<xs:simpleType name="SmallDressSizeType"> <xs:restriction base="DressSizeType"> <xs:minInclusive value="0"/> <xs:maxInclusive value="6"/> </xs:restriction> </xs:simpleType>
<xs:simpleType name="DressSizeType"> <xs:restriction base="xs:integer"> <xs:minInclusive value="2" fixed="true"/> <xs:maxInclusive value="18" fixed="true"/> <xs:pattern value="\d{1,2}"/> </xs:restriction> </xs:simpleType>
<xs:simpleType name="DressSizeType"> <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=""/> </xs:restriction> </xs:simpleType> </xs:union> </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>
<xs:simpleType name="SMLSizeType"> <xs:restriction base="SMLXSizeType"> <xs:enumeration value="small"/> <xs:enumeration value="medium"/> <xs:enumeration value="large"/> </xs:restriction> </xs:simpleType>
<xs:simpleType name="XSMLXSizeType"> <xs:restriction base="SMLXSizeType"> <xs:enumeration value="extra small"/> <xs:enumeration value="small"/> <xs:enumeration value="medium"/> <xs:enumeration value="large"/> <xs:enumeration value="extra large"/> </xs:restriction> </xs:simpleType>
<xs:simpleType name="XSMLXSizeType"> <xs:union memberTypes="SMLXSizeType"> <xs:simpleType> <xs:restriction base="xs:token"> <xs:enumeration value="extra small"/> </xs:restriction> </xs:simpleType> </xs:union> </xs:simpleType>
<xs:simpleType name="NewSmallDressSizeType"> <xs:restriction base="xs:integer"> <xs:enumeration value="2"/> <xs:enumeration value="4"/> <xs:enumeration value="6"/> </xs:restriction> </xs:simpleType>
<size>2</size> <size>02</size>
<xs:simpleType name="DressSizeType"> <xs:restriction base="xs:integer"> <xs:minInclusive value="2"/> <xs:maxInclusive value="18"/> <xs:pattern value="\d{1,2}"/> </xs:restriction> </xs:simpleType>
<xs:simpleType name="SmallDressSizeType"> <xs:restriction base="DressSizeType"> <xs:minInclusive value="2"/> <xs:maxInclusive value="6"/> <xs:pattern value="\d{1}"/> </xs:restriction> </xs:simpleType>
<xs:simpleType name="LongerDressSizeType"> <xs:restriction base="DressSizeType"> <xs:pattern value="\d{1,3}"/> </xs:restriction> </xs:simpleType>
<xs:simpleType name="EvenDressSizeType"> <xs:restriction base="DressSizeType"> <xs:assertion test="$value mod 2 = 0"/> </xs:restriction> </xs:simpleType>
<xs:simpleType name="SpecificTimeType"> <xs:restriction base="xs:time"> <xs:explicitTimezone value="required"/> </xs:restriction> </xs:simpleType>
<size> small </size> <size>extra large</size>
<xs:simpleType name="DressSizeType" final="restriction list"> <xs:restriction base="xs:integer"> <xs:minInclusive value="2"/> <xs:maxInclusive value="18"/> </xs:restriction> </xs:simpleType>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:ext="http://example.org/extensions"> <xs:element name="anyOrdinalDate" type="ext:ordinalDate"/> <xs:element name="recentOrdinalDate" type="OrdinalDateIn2011"/> <xs:simpleType name="OrdinalDateIn2011"> <xs:restriction base="ext:ordinalDate"> <xs:minInclusive value="2011-001"/> <xs:maxInclusive value="2011-365"/> </xs:restriction> </xs:simpleType> </xs:schema>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:saxon="http://saxon.sf.net/"> <xs:simpleType name="SMLXSizeType"> <xs:restriction base="xs:token"> <saxon:preprocess action="upper-case($value)"/> <xs:enumeration value="SMALL"/> <xs:enumeration value="MEDIUM"/> <xs:enumeration value="LARGE"/> <xs:enumeration value="EXTRA LARGE"/> </xs:restriction> </xs:simpleType> </xs:schema>