Definitive XML Schema
Priscilla Walmsley (pwalmsley@datypic.com)
ISBN: 0130655678
1st edition, , Prentice Hall PTR.
Chapter 21: Extensibility and reuse
Book examples
<xsd:complexType name="ProductType"> <xsd:sequence> <xsd:element name="number" type="ProdNumType"/> <xsd:element name="name" type="xsd:string"/> <xsd:element name="size" type="SizeType" minOccurs="0"/> <xsd:any minOccurs="0" maxOccurs="unbounded" namespace="##other" processContents="lax"/> </xsd:sequence> <xsd:anyAttribute namespace="##other" processContents="skip"/> </xsd:complexType>
<order xmlns="http://example.org/ord" xmlns:spc="http://example.org/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>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://example.org/spc" targetNamespace="http://example.org/spc"> <xsd:element name="giftWrap" type="GiftWrapType"/> <xsd:attribute name="points" type="xsd:nonNegativeInteger"/> </xsd:schema>
<xsd:complexType name="ProductType"> <xsd:sequence> <xsd:element name="number" type="ProdNumType"/> <xsd:element name="name" type="xsd:string"/> <xsd:element name="size" type="SizeType" minOccurs="0"/> </xsd:sequence> </xsd:complexType>
<xsd:complexType name="ExtendedProductType"> <xsd:complexContent> <xsd:extension base="ProductType"> <xsd:sequence> <xsd:element ref="spc:giftWrap" minOccurs="0"/> </xsd:sequence> <xsd:attribute ref="spc:points"/> </xsd:extension> </xsd:complexContent> </xsd:complexType>
<order xmlns="http://example.org/ord" xmlns:spc="http://example.org/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>
<xsd:complexType name="ItemsType"> <xsd:choice maxOccurs="unbounded"> <xsd:element ref="shirt"/> <xsd:element ref="hat"/> <xsd:element ref="umbrella"/> </xsd:choice> </xsd:complexType> <xsd:complexType name="ExpandedItemsType"> <xsd:complexContent> <xsd:extension base="ItemsType"> <xsd:choice maxOccurs="unbounded"> <xsd:element ref="sweater"/> <xsd:element ref="suit"/> </xsd:choice> </xsd:extension> </xsd:complexContent> </xsd:complexType>
<xsd:complexType name="ItemsType"> <xsd:choice maxOccurs="unbounded"> <xsd:element ref="shirt"/> <xsd:element ref="hat"/> <xsd:element ref="umbrella"/> <xsd:element ref="otherProduct"/> </xsd:choice> </xsd:complexType> <xsd:element name="otherProduct" type="ProductType" abstract="true"/>
<xsd:element name="sweater" substitutionGroup="otherProduct"/> <xsd:element name="suit" substitutionGroup="otherProduct"/>
<items> <shirt>...</shirt> <sweater>...</sweater> <shirt>...</shirt> <suit>...</suit> </items>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:spc="http://example.org/spc" xmlns="http://example.org/ord" targetNamespace="http://example.org/ord"> <xsd:import namespace="http://example.org/spc"/> <xsd:redefine schemaLocation="original.xsd"> <xsd:complexType name="ProductType"> <xsd:complexContent> <xsd:extension base="ProductType"> <xsd:sequence> <xsd:element ref="spc:giftWrap" minOccurs="0"/> </xsd:sequence> <xsd:attribute ref="spc:points"/> </xsd:extension> </xsd:complexContent> </xsd:complexType> </xsd:redefine> </xsd:schema>
<xsd:complexType name="ProductType"> <xsd:group ref="ProductPropertyGroup"/> <xsd:attributeGroup ref="ExtensionGroup"/> </xsd:complexType> <xsd:group name="ProductPropertyGroup"> <xsd:sequence> <xsd:element name="number" type="ProdNumType"/> <xsd:element name="name" type="xsd:string"/> <xsd:element name="size" type="SizeType" minOccurs="0"/> </xsd:sequence> </xsd:group> <xsd:attributeGroup name="ExtensionGroup"/>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:spc="http://example.org/spc" xmlns="http://example.org/ord" targetNamespace="http://example.org/ord"> <xsd:import namespace="http://example.org/spc"/> <xsd:redefine schemaLocation="original.xsd"> <xsd:group name="ProductPropertyGroup"> <xsd:sequence> <xsd:element ref="spc:giftWrap"/> <xsd:group ref="ProductPropertyGroup"/> </xsd:sequence> </xsd:group> <xsd:attributeGroup name="ExtensionGroup"> <xsd:attributeGroup ref="ExtensionGroup"/> <xsd:attribute ref="spc:points"/> </xsd:attributeGroup> </xsd:redefine> </xsd:schema>
<order xmlns="http://example.org/ord" xmlns:spc="http://example.org/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>