共用方式為


類型

指定項目的型別。 這個屬性將項目標示為特定型別,就算結構描述中可能沒有將該項目繫結至型別的項目宣告。

<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>

請參閱

參考

XML 結構描述 (XSD) 參考

XML 結構描述元素

XML 結構描述執行個體屬性