Definitive XML Schema
Priscilla Walmsley (pwalmsley@datypic.com)
ISBN: 0130655678
1st edition, , Prentice Hall PTR.
Chapter 9: 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
<xsd:simpleType name="DressSizeType"> <xsd:restriction base="xsd:integer"> <xsd:minInclusive value="2"/> <xsd:maxInclusive value="18"/> </xsd:restriction> </xsd:simpleType> <xsd:element name="size" type="DressSizeType"/>
<xsd:element name="size"> <xsd:simpleType> <xsd:restriction base="xsd:integer"> <xsd:minInclusive value="2"/> <xsd:maxInclusive value="18"/> </xsd:restriction> </xsd:simpleType> </xsd:element>
<xsd:simpleType name="DressSizeType"> <xsd:restriction base="xsd:integer"> <xsd:minInclusive value="2"/> <xsd:maxInclusive value="18"/> <xsd:pattern value="\d{1,2}"/> </xsd:restriction> </xsd:simpleType>
<xsd:simpleType name="MediumDressSizeType"> <xsd:restriction base="DressSizeType"> <xsd:minInclusive value="8"/> <xsd:maxInclusive value="12"/> </xsd:restriction> </xsd:simpleType>
<xsd:simpleType name="MediumDressSizeType"> <xsd:restriction base="xsd:integer"> <xsd:minInclusive value="8"/> <xsd:maxInclusive value="12"/> <xsd:pattern value="\d{1,2}"/> </xsd:restriction> </xsd:simpleType>
<xsd:simpleType name="SmallDressSizeType"> <xsd:restriction base="DressSizeType"> <xsd:minInclusive value="0"/> <xsd:maxInclusive value="6"/> </xsd:restriction> </xsd:simpleType>
<xsd:simpleType name="DressSizeType"> <xsd:restriction base="xsd:integer"> <xsd:minInclusive value="2" fixed="true"/> <xsd:maxInclusive value="18" fixed="true"/> <xsd:pattern value="\d{1,2}"/> </xsd:restriction> </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>
<xsd:simpleType name="SMLSizeType"> <xsd:restriction base="SMLXSizeType"> <xsd:enumeration value="small"/> <xsd:enumeration value="medium"/> <xsd:enumeration value="large"/> </xsd:restriction> </xsd:simpleType>
<xsd:simpleType name="XSMLXSizeType"> <xsd:restriction base="SMLXSizeType"> <xsd:enumeration value="extra small"/> <xsd:enumeration value="small"/> <xsd:enumeration value="medium"/> <xsd:enumeration value="large"/> <xsd:enumeration value="extra large"/> </xsd:restriction> </xsd:simpleType>
<xsd:simpleType name="XSMLXSizeType"> <xsd:union memberTypes="SMLXSizeType"> <xsd:simpleType> <xsd:restriction base="xsd:token"> <xsd:enumeration value="extra small"/> </xsd:restriction> </xsd:simpleType> </xsd:union> </xsd:simpleType>
<xsd:simpleType name="NewSmallDressSizeType"> <xsd:restriction base="xsd:integer"> <xsd:enumeration value="2"/> <xsd:enumeration value="4"/> <xsd:enumeration value="6"/> </xsd:restriction> </xsd:simpleType>
<size>2</size> <size>02</size>
<xsd:simpleType name="DressSizeType"> <xsd:restriction base="xsd:integer"> <xsd:minInclusive value="2"/> <xsd:maxInclusive value="18"/> <xsd:pattern value="\d{1,2}"/> </xsd:restriction> </xsd:simpleType>
<xsd:simpleType name="SmallDressSizeType"> <xsd:restriction base="DressSizeType"> <xsd:minInclusive value="2"/> <xsd:maxInclusive value="6"/> <xsd:pattern value="\d{1}"/> </xsd:restriction> </xsd:simpleType>
<xsd:simpleType name="LongerDressSizeType"> <xsd:restriction base="DressSizeType"> <xsd:pattern value="\d{1,3}"/> </xsd:restriction> </xsd:simpleType>
<size> small </size> <size>extra large</size>
<final="#all" final="restriction list union" final="list restriction extension" final="union">final=""
<xsd:simpleType name="DressSizeType" final="restriction list"> <xsd:restriction base="xsd:integer"> <xsd:minInclusive value="2"/> <xsd:maxInclusive value="18"/> </xsd:restriction> </xsd:simpleType>