If you have elements in your XML file whose type is a complex type,
xsi:type support in the XML editor lets you choose between the complex type
and any other complex types derived from it.
The XML Schema specification allows you to derive types by extension.
See the following steps as an example:
- Create an XML schema and create a complex type for it called Address.
- Add some basic elements to Address, such
as streetName and city.
- Derive (by extension) two new complex types from Address: USAddress and UKAddress.
- Add a new element to USAddress called state,
and also a new element to UKAddress called postcode.
- Create two more elements: billTo and shipTo,
as Address types.
- When you create an XML instance document for an element such as
billTo or Address, an
xsi:type attribute will automatically be added to it. For example,
<billTo xsi:type="ipo:Address">
The
xsi:type attribute is used to identify derived complex types (as well as complex
types that have been derived from).
- In the Design view of the XML editor, a list will be available,
letting you select the appropriate type definition (Address, USAddress,
or UKAddress). The guided editing for the content
model will reflect the type definition that you choose. For example, if you
select USAddress , your billTo element
can contain a state element, but it cannot contain a postcode element.
The XML example "Editing and validating XML files" demonstrates xsi:type support.
For
more information about xsi:type, refer to the Using Derived Types in Instance
Documents section in XML Schema Part 0: Primer.
For more information
about validation semantics when xsi:type is used, refer to the Schema-Related
Markup in Documents Being Validated section in XML Schema Part 1: Structures