Definitive XML Schema
Priscilla Walmsley (pwalmsley@datypic.com)
ISBN: 0132886723
2nd edition, , Prentice Hall PTR.
Chapter 22: Extensibility and reuse
Book examples
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="http://datypic.com/common" xmlns="http://datypic.com/common" elementFormDefault="qualified"> <xs:simpleType name="ProductIDType"> <xs:restriction base="xs:string"> <xs:pattern value="[A-Z]{2}[0-9]{4}"/> </xs:restriction> </xs:simpleType> <xs:complexType name="PriceType"> <xs:simpleContent> <xs:extension base="xs:decimal"> <xs:attribute name="currency" type="CurrencyCodeType"/> </xs:extension> </xs:simpleContent> </xs:complexType> <xs:complexType name="MeasurementType"> <xs:simpleContent> <xs:extension base="xs:decimal"> <xs:attribute name="units" type="UnitsCodeType"/> </xs:extension> </xs:simpleContent> </xs:complexType> <xs:complexType name="AddressType"> <xs:sequence> <xs:element name="street" type="xs:string" maxOccurs="3"/> <xs:element name="city" type="xs:string"/> <xs:element name="state" type="xs:string"/> <xs:element name="postalCode" type="xs:string"/> <xs:element name="country" type="xs:string"/> </xs:sequence> </xs:complexType> <!--...--> </xs:schema>
<xs:complexType name="ProductType"> <xs:sequence> <xs:element name="number" type="xs:integer"/> <xs:element name="name" type="xs:string"/> <xs:element name="size" type="xs:integer" minOccurs="0"/> <xs:any minOccurs="0" maxOccurs="unbounded" namespace="##other" processContents="lax"/> </xs:sequence> <xs:anyAttribute namespace="##other" processContents="skip"/> </xs:complexType>
<order xmlns="http://datypic.com/ord" xmlns:spc="http://datypic.com/spc"> <product spc:points="100"> <number>557</number> <name>Short-Sleeved Linen Blouse</name> <size>10</size> <spc:giftWrap>ADULT BDAY</spc:giftWrap> </product> </order>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns="http://datypic.com/spc" targetNamespace="http://datypic.com/spc"> <xs:element name="giftWrap" type="xs:string"/> <xs:attribute name="points" type="xs:nonNegativeInteger"/> </xs:schema>
<xs:complexType name="ProductType"> <xs:openContent> <xs:any namespace="##other" processContents="lax"/> </xs:openContent> <xs:sequence> <xs:element name="number" type="xs:integer"/> <xs:element name="name" type="xs:string"/> <xs:element name="size" type="xs:integer" minOccurs="0"/> </xs:sequence> <xs:anyAttribute namespace="##other" processContents="skip"/> </xs:complexType>
<order xmlns="http://datypic.com/ord" xmlns:spc="http://datypic.com/spc"> <product spc:points="100"> <number>557</number> <spc:giftWrap>ADULT BDAY</spc:giftWrap> <name>Short-Sleeved Linen Blouse</name> <size>10</size> </product> </order>
<xs:complexType name="ProductType"> <xs:sequence> <xs:element name="number" type="xs:integer"/> <xs:element name="name" type="xs:string"/> <xs:element name="size" type="xs:integer" minOccurs="0"/> </xs:sequence> </xs:complexType>
<xs:complexType name="ExtendedProductType"> <xs:complexContent> <xs:extension base="ProductType"> <xs:sequence> <xs:element ref="spc:giftWrap" minOccurs="0"/> </xs:sequence> <xs:attribute ref="spc:points"/> </xs:extension> </xs:complexContent> </xs:complexType>
<order xmlns="http://datypic.com/ord" xmlns:spc="http://datypic.com/spc" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <product spc:points="100" xsi:type="ExtendedProductType"> <number>557</number> <name>Short-Sleeved Linen Blouse</name> <size>10</size> <spc:giftWrap>ADULT BDAY</spc:giftWrap> </product> </order>
<xs:complexType name="ItemsType"> <xs:choice maxOccurs="unbounded"> <xs:element ref="shirt"/> <xs:element ref="hat"/> <xs:element ref="umbrella"/> </xs:choice> </xs:complexType> <xs:complexType name="ExpandedItemsType"> <xs:complexContent> <xs:extension base="ItemsType"> <xs:choice maxOccurs="unbounded"> <xs:element ref="sweater"/> <xs:element ref="suit"/> </xs:choice> </xs:extension> </xs:complexContent> </xs:complexType>
<xs:complexType name="ItemsType"> <xs:choice maxOccurs="unbounded"> <xs:element ref="shirt"/> <xs:element ref="hat"/> <xs:element ref="umbrella"/> <xs:element ref="otherProduct"/> </xs:choice> </xs:complexType> <xs:element name="otherProduct" type="ProductType" abstract="true"/>
<xs:element name="sweater" substitutionGroup="otherProduct"/> <xs:element name="suit" substitutionGroup="otherProduct"/>
<items> <shirt>...</shirt> <sweater>...</sweater> <shirt>...</shirt> <suit>...</suit> </items>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:spc="http://datypic.com/spc" xmlns="http://datypic.com/ord" targetNamespace="http://datypic.com/ord"> <xs:import namespace="http://datypic.com/spc"/> <xs:redefine schemaLocation="original.xsd"> <xs:complexType name="ProductType"> <xs:complexContent> <xs:extension base="ProductType"> <xs:sequence> <xs:element ref="spc:giftWrap" minOccurs="0"/> </xs:sequence> <xs:attribute ref="spc:points"/> </xs:extension> </xs:complexContent> </xs:complexType> </xs:redefine> </xs:schema>
<xs:complexType name="ProductType"> <xs:group ref="ProductPropertyGroup"/> <xs:attributeGroup ref="ExtensionGroup"/> </xs:complexType> <xs:group name="ProductPropertyGroup"> <xs:sequence> <xs:element name="number" type="xs:integer"/> <xs:element name="name" type="xs:string"/> <xs:element name="size" type="xs:integer" minOccurs="0"/> </xs:sequence> </xs:group> <xs:attributeGroup name="ExtensionGroup"/>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:spc="http://datypic.com/spc" xmlns="http://datypic.com/ord" targetNamespace="http://datypic.com/ord"> <xs:import namespace="http://datypic.com/spc"/> <xs:redefine schemaLocation="original.xsd"> <xs:group name="ProductPropertyGroup"> <xs:sequence> <xs:element ref="spc:giftWrap"/> <xs:group ref="ProductPropertyGroup"/> </xs:sequence> </xs:group> <xs:attributeGroup name="ExtensionGroup"> <xs:attributeGroup ref="ExtensionGroup"/> <xs:attribute ref="spc:points"/> </xs:attributeGroup> </xs:redefine> </xs:schema>
<order xmlns="http://datypic.com/ord" xmlns:spc="http://datypic.com/spc"> <product spc:points="100"> <spc:giftWrap>ADULT BDAY</spc:giftWrap> <number>557</number> <name>Short-Sleeved Linen Blouse</name> <size>10</size> </product> </order>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:spc="http://datypic.com/spc" xmlns="http://datypic.com/ord" targetNamespace="http://datypic.com/ord" elementFormDefault="qualified"> <xs:import namespace="http://datypic.com/spc"/> <xs:override schemaLocation="original.xsd"> <xs:complexType name="ProductType"> <xs:sequence> <xs:element name="number" type="xs:integer"/> <xs:element name="name" type="xs:string"/> <xs:element name="size" type="xs:integer" minOccurs="0"/> <xs:element ref="spc:giftWrap" minOccurs="0"/> </xs:sequence> <xs:attribute ref="spc:points"/> </xs:complexType> </xs:override> </xs:schema>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:spc="http://datypic.com/spc" xmlns="http://datypic.com/ord" targetNamespace="http://datypic.com/ord" elementFormDefault="qualified"> <xs:import namespace="http://datypic.com/spc"/> <xs:override schemaLocation="original.xsd"> <xs:group name="ProductPropertyGroup"> <xs:sequence> <xs:element ref="spc:giftWrap"/> <xs:element name="number" type="xs:integer"/> <xs:element name="name" type="xs:string"/> <xs:element name="size" type="xs:integer" minOccurs="0"/> </xs:sequence> </xs:group> <xs:attributeGroup name="ExtensionGroup"> <xs:attribute ref="spc:points"/> </xs:attributeGroup> </xs:override> </xs:schema>
<order xmlns="http://datypic.com/ord" xmlns:spc="http://datypic.com/spc"> <product spc:points="100"> <spc:giftWrap>ADULT BDAY</spc:giftWrap> <number>557</number> <name>Short-Sleeved Linen Blouse</name> <size>10</size> </product> </order>