type

MSXML 5.0 SDK

Microsoft XML Core Services (MSXML) 5.0 for Microsoft Office - XML Schemas

type

Specifies the type of an element. This attribute labels an element as a particular type, even though there might not be an element declaration in the schema binding that element to the type.

<xsi:type="QName">

Attributes

QName
The name of the data type that is being substituted for the element's declared data type.

Remarks

The type attribute is also used when derived complex types are used in instance documents intead of the expected base type.

Example

The following example shows the use of type attribute. The example uses a schema document, person.xsd, and an instance document, person.xml. The schema document contains a base type Person, a derived type Employee, and an element declaration person. The instance document shows the use of the xsi:type attribute to specify that the person element in the urn:contoso-com:People namespace is of the type Employee in the same namespace.

<!-- person.xsd -->
<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>

<!-- person.xml -->
<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>

See Also

XML Schema Reference | XML Schema Elements | XML Schema Instance Attributes