要素の型を指定します。スキーマ内に、要素を型にバインドする要素宣言がない場合でも、要素を特定の型として指定します。
<xsi:type="QName">
属性
- QName
要素の宣言されたデータ型の代わりに使用されるデータ型の名前。
解説
インスタンス ドキュメントで、通常の基本型の代わりに、派生した複合型が使用されている場合にも、type 属性が使用されます。
例
type 属性の使用方法を次の例に示します。この例では、スキーマ ドキュメント person.xsd とインスタンス ドキュメント person.xml が使用されています。スキーマ ドキュメントには、基本型の Person、派生型の Employee、および要素宣言の person が含まれています。インスタンス ドキュメントには、xsi:type 属性の使い方が示されています。つまり、この属性は、urn:contoso-com:People 名前空間の要素 person は同じ名前空間の Employee 型であることを示しています。
<xs:schema xmlns:xs= "http://www.w3.org/2001/XMLSchema"
targetNamespace="urn:contoso-com:People"
xmlns:ns="urn:contoso-com:People">
<xs:element name="person" type="ns:Person"/>
<xs:complexType name="Person">
<xs:sequence>
<xs:element name= "name" type="xs:string"/>
<xs:element name= "height" type="xs:double" />
</xs:sequence>
</xs:complexType>
<xs:complexType name="Employee">
<xs:complexContent>
<xs:extension base="ns:Person">
<xs:sequence>
<xs:element name="jobDescription" type="xs:string" />
</xs:sequence>
</xs:extension>
</xs:complexContent>
</xs:complexType>
</xs:schema>
<p:Person
xmlns:p="urn:contoso-com:People"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:type="p:Employee">
<name>John</name>
<height>59</height>
<jobDescription>manager</jobDescription>
</p:Person>