Abstract types
Declaring a type as abstract requires the use of a type derived from it, and
identified by the xsi:type
attribute, in the instance
document.
After the IDE determines an element’s type is abstract, the element should not be expanded until it is substituted. The element whose type is abstract is rendered in italic type. You can right-click the element node and substitute its type. Then, address an address pointing to the substituted type. The substituted element does not show the abstract icon because only non-abstract types can substitute abstract elements.
Declaring a type as abstract
In the schema definition, a type can be declared abstract
.
<xsd:complexType name="xxx" abstract="true">...
This declaration means that elements that are declared with this type
must have their types re-declared in an XML instance. To do this, use an xsi:type
attribute to declare a non-abstract type derived
from this abstract type. Elements that are declared with this type that do not have an
xsi:type
attribute are incorrect.
For example, using the previous example but making
base_type
an abstract type creates:
<xsd:element name="myElement" type="base_type"/>
<xsd:complexType name="base_type" abstract="true">
<xsd:sequence>
<xsd:element name="myChild1" type="xsd:string"/>
</xsd:sequence>
</xsd:complexType>
<xsd:complexType name="derived_type">
<xsd:complexContent>
<xsd:extension base="base_type">
<xsd:sequence>
<xsd:element name="myChild2" type="xsd:string"/>
</xsd:sequence>
</xsd:extension>
</xsd:complexContent>
</xsd:complexType>
These XML instances would no longer conform:
<myElement><myChild1/></myElement>
<myElement xsi:type="base_type"><myChild1/></myElement>
In this case, a non-abstract type must be declared. This instance would still conform:
<myElement xsi:type="derived_type">
<myChild1/>
<myChild2/>
</myElement>
This is a schema element declaration for compile:
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" elementFormDefault="unqualified" attributeFormDefault="unqualified">
<xsd:element name="myElement" type="base_type"/>
<xsd:complexType name="base_type" abstract="true">
<xsd:sequence>
<xsd:element name="myChild1" type="xsd:string"/>
</xsd:sequence>
</xsd:complexType>
<xsd:complexType name="derived_type">
<xsd:complexContent>
<xsd:extension base="base_type">
<xsd:sequence>
<xsd:element name="myChild2" type="xsd:string"/>
</xsd:sequence>
</xsd:extension>
</xsd:complexContent>
</xsd:complexType>
</xsd:schema>