XML スキーマ仕様では、拡張により、複合タイプを派生させる機能が サポートされています。
XML インスタンス文書では、 XML スキーマ内で XML エレメントのタイプを明示的に宣言する代わりに、 すべて同じ基本タイプから派生するタイプのセットから、 XML エレメントのタイプを宣言します。エレメントのタイプは、 次の XML インスタンス文書の例に示すように、type 属性を使用して 定義されます。
<?xml version="1.0" encoding="UTF-8"?> <shape xmlns="http://shapesrus.com/example" xmlns:xsd="http://www.w3.org/2001/XMLSchema-instance" xsd:type="circle"> <color xmlns="">blue</color> <diameter xmlns="">10</diameter> </shape>
上記の XML インスタンス文書で、 <shape> エレメントは circle タイプとして宣言されています。 XML インスタンス文書内の <shape> エレメントは、 次の XML インスタンス文書の例で定義されているように、 rectangle タイプとして定義することもできます。
<?xml version="1.0" encoding="UTF-8"?> <shape xmlns="http://shapesrus.com/example" xmlns:xsd="http://www.w3.org/2001/XMLSchema-instance" xsd:type="rectangle"> <color xmlns="">blue</color> <length xmlns="">5</length> <width xmlns="">8</width> </shape>この例で、<shape> エレメントは、 shapeType 基本タイプの派生型の 1 つに 基づいています。shapeType の派生型の名前は、次の XML スキーマの例に示すように、 circle および rectangle です。
上記の XML スキーマの例で、 <shapeType> と呼ばれる基本タイプは 抽象的なものとして定義されています。XML インスタンス文書で抽象的な基本タイプを使用して エレメントのタイプを定義することはできません。その代わりに派生型の 1 つを 指定する必要があります。この例で、XML インスタンス文書内の <shape> エレメント を shapeType として宣言することはできません。 派生型の 1 つ (circle または rectangle) として宣言する必要があります。
<xsd:complexType name="shapeType"> <xsd:sequence> <xsd:element name="color" type="xsd:string"/> </xsd:sequence> </xsd:complexType>WSDL は、Web サービスを定義する固有の XML スキーマ です。WSDL でのタイプ置換の使用も サポートされています。
繰り返し宛先ノードの 展開されたオカレンス の置換タイプを指定できます。展開されたオカレンスのタイプの置換は、 繰り返し宛先ノードでのみサポートされます。宛先ノードはマッピング・ペインの右側にあります。
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" targetNamespace="http://shapesrus.com/example" xmlns:sru="http://shapesrus.com/example"> <xsd:element name="shape" type="sru:shapeType"/> <xsd:complexType name="shapeType" abstract="true"> <xsd:sequence> <xsd:element name="color" type="xsd:string"/> </xsd:sequence> </xsd:complexType> <xsd:complexType name="circle"> <xsd:complexContent> <xsd:extension base="sru:shapeType"> <xsd:sequence> <xsd:element name="diameter" type="xsd:integer"/> </xsd:sequence> </xsd:extension> </xsd:complexContent> </xsd:complexType> <xsd:complexType name="rectangle"> <xsd:complexContent> <xsd:extension base="sru:shapeType"> <xsd:sequence> <xsd:element name="length" type="xsd:integer"/> <xsd:element name="width" type="xsd:integer"/> </xsd:sequence> </xsd:extension> </xsd:complexContent> </xsd:complexType> </xsd:schema>