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 인스턴스 문서에 정의된 것과 같이, XML 인스턴스 문서의 <shape> 요소는 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 기본 유형의 파생 유형 중 하나를 기반으로 합니다. shapeType에서 파생된 유형의 이름은 circle 및 rectangle입니다 (다음 예제 XML 스키마 참조).
위에 표시된 예제 XML 스키마에서 기본 유형 <shapeType>이 추상으로 정의됩니다. 추상 기본 유형은 XML 인스턴스 문서에서 요소의 유형을 정의하는 데 사용할 수 없습니다. 파생된 유형 중 하나를 대신 지정해야 합니다. 이 예제에서, XML 인스턴스 문서의 <shape> 요소를 shapeType으로 선언할 수 없습니다. 파생된 유형인 circle 또는 rectangle 중 하나로 선언해야 합니다.
<xsd:complexType name="shapeType"> <xsd:sequence> <xsd:element name="color" type="xsd:string"/> </xsd:sequence> </xsd:complexType>WSDL은 웹 서비스를 정의하는 특정 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>