xsi:type
The xsi:type
attribute may be used in instance documents to
indicate the type of an element, even when a full schema is not
available. For example, this length
element has type xs:decimal
:
<length xsi:type="xs:decimal">23.5</length>
More importantly, the xsi:type
attribute enables a limited
form of polymorphism. That is, it allows you to make an element an
instance of a derived type where an instance of the base type
would normally be expected. The instance of the derived type must
carry an xsi:type
attribute
identifying it as an instance of the derived type.
For example, suppose a schema says that a ticket
element has type TicketType
. If the schema also defines
BusTicketType
and AirplaneTicketType
elements as subtypes
of TicketType
, then a ticket
element could also use the
BusTicketType
and AirplaneTicketType
content models
provided it had an xsi:type="BusTicketType
" or xsi:type="AirplaneTicketType
" attribute.