このサンプルでは,スキーマ文書として,purchaseOrder.xsd,およびpersonalData.xsdを使用します。
purchaseOrder.xsd,およびpersonalData.xsdでの各名前空間の関係を図5-5に示します。それぞれの矢印は,参照する型定義や要素などが定義された対象名前空間を指しています。
図5-5 スキーマ文書の名前空間の関係
使用するスキーマ文書(purchaseOrder.xsd)を次に示します。
<?xml version="1.0"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.myshopping.com/schema/purchaseOrder"
xmlns:po="http://www.myshopping.com/schema/purchaseOrder"
xmlns:psd="http://www.myshopping.com/schema/personalData">
<xsd:import
namespace="http://www.myshopping.com/schema/personalData"
schemaLocation="personalData.xsd"/>
<xsd:element name="purchaseOrder" type="po:purchaseOrderType"/>
<xsd:element name="shipTo" type="psd:personalDataType"/>
<xsd:element name="billTo" type="po:billToPersonalDataType"/>
<xsd:element name="items" type="po:itemsType">
<xsd:key name="productID_unique">
<xsd:selector xpath="po:item/po:productName"/>
<xsd:field xpath="@productID"/>
</xsd:key>
</xsd:element>
<xsd:element name="item" type="po:itemType"/>
<xsd:element name="productName" type="po:productNameType"/>
<xsd:element name="quantity">
<xsd:simpleType>
<xsd:restriction base="xsd:positiveInteger">
<xsd:maxExclusive value="100"/>
</xsd:restriction>
</xsd:simpleType>
</xsd:element>
<xsd:element name="price" type="xsd:positiveInteger"/>
<xsd:element name="shipDate" type="xsd:date"/>
<xsd:element name="credit" type="po:creditType"/>
<xsd:element name="creditHolder" type="xsd:string"/>
<xsd:element name="creditNumber">
<xsd:simpleType>
<xsd:restriction base="xsd:string">
<xsd:pattern value="¥d{16}"/>
</xsd:restriction>
</xsd:simpleType>
</xsd:element>
<xsd:element name="creditCompany">
<xsd:simpleType>
<xsd:restriction base="xsd:string">
<xsd:enumeration value="CardCompanyA"/>
<xsd:enumeration value="CardCompanyB"/>
<xsd:enumeration value="CardCompanyC"/>
<xsd:enumeration value="CardCompanyD"/>
</xsd:restriction>
</xsd:simpleType>
</xsd:element>
<xsd:complexType name="purchaseOrderType">
<xsd:sequence>
<xsd:element ref="po:shipTo"/>
<xsd:element ref="po:billTo"/>
<xsd:element ref="po:items"/>
</xsd:sequence>
</xsd:complexType>
<xsd:complexType name="billToPersonalDataType">
<xsd:sequence>
<xsd:group ref="psd:personalDataGroup"/>
<xsd:element ref="po:credit"/>
</xsd:sequence>
<xsd:attributeGroup ref="psd:personalAttributeGroup"/>
</xsd:complexType>
<xsd:complexType name="itemsType">
<xsd:sequence>
<xsd:element ref="po:item"
minOccurs="0" maxOccurs="unbounded"/>
</xsd:sequence>
</xsd:complexType>
<xsd:complexType name="itemType">
<xsd:sequence>
<xsd:element ref="po:productName"/>
<xsd:element ref="po:quantity"/>
<xsd:element ref="po:price"/>
<xsd:element ref="po:shipDate"/>
</xsd:sequence>
</xsd:complexType>
<xsd:complexType name="productNameType">
<xsd:simpleContent>
<xsd:extension base="xsd:string">
<xsd:attribute name="productID" type="xsd:string"/>
</xsd:extension>
</xsd:simpleContent>
</xsd:complexType>
<xsd:complexType name="creditType">
<xsd:sequence>
<xsd:element ref="po:creditHolder"/>
<xsd:element ref="po:creditNumber"/>
<xsd:element ref="po:creditCompany"/>
</xsd:sequence>
<xsd:attribute name="year" type="po:yearType" use="required"/>
<xsd:attribute name="month" type="po:monthType" use="required"/>
</xsd:complexType>
<xsd:simpleType name="yearType">
<xsd:annotation>
<xsd:documentation>
Year set from 2004 to 2008
</xsd:documentation>
</xsd:annotation>
<xsd:restriction base="xsd:string">
<xsd:pattern value="200[4-8]"/>
</xsd:restriction>
</xsd:simpleType>
<xsd:simpleType name="monthType">
<xsd:restriction base="xsd:string">
<xsd:pattern value="0[1-9]|1[0-2]"/>
</xsd:restriction>
</xsd:simpleType>
</xsd:schema>
使用するスキーマ文書(personalData.xsd)を次に示します。
<?xml version="1.0"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.myshopping.com/schema/personalData"
xmlns:psd="http://www.myshopping.com/schema/personalData">
<xsd:element name="personalData" type="psd:personalDataType"/>
<xsd:element name="firstName" type="xsd:string"/>
<xsd:element name="familyName" type="xsd:string"/>
<xsd:element name="occupation" type="xsd:string"/>
<xsd:element name="email" type="xsd:string"/>
<xsd:element name="tel" type="xsd:string"/>
<xsd:element name="address" type="psd:addressType"/>
<xsd:element name="building" type="xsd:string"/>
<xsd:element name="street" type="xsd:string"/>
<xsd:element name="city" type="xsd:string"/>
<xsd:element name="state" type="xsd:string"/>
<xsd:element name="zip" type="xsd:string"/>
<xsd:complexType name="personalDataType">
<xsd:group ref="psd:personalDataGroup"/>
<xsd:attributeGroup ref="psd:personalAttributeGroup"/>
</xsd:complexType>
<xsd:group name="personalDataGroup">
<xsd:sequence>
<xsd:element ref="psd:firstName"/>
<xsd:element ref="psd:familyName"/>
<xsd:element ref="psd:occupation"/>
<xsd:element ref="psd:email"/>
<xsd:element ref="psd:tel"/>
<xsd:element ref="psd:address"/>
</xsd:sequence>
</xsd:group>
<xsd:attributeGroup name="personalAttributeGroup">
<xsd:attribute name="age"
type="xsd:positiveInteger" use="optional"/>
<xsd:attribute name="company"
type="xsd:string" use="optional"/>
<xsd:attribute name="department"
type="xsd:string" use="optional"/>
<xsd:attribute name="title"
type="xsd:string" use="optional"/>
<xsd:attribute name="fax"
type="xsd:string" use="optional"/>
</xsd:attributeGroup>
<xsd:complexType name="addressType">
<xsd:sequence>
<xsd:element ref="psd:building" minOccurs="0"/>
<xsd:element ref="psd:street"/>
<xsd:element ref="psd:city"/>
<xsd:element ref="psd:state"/>
<xsd:element ref="psd:zip"/>
</xsd:sequence>
<xsd:attribute name="country" type="xsd:string"
use="optional" default="US"/>
</xsd:complexType>
</xsd:schema>