Selecting a substitution type

The XML Schema specification supports the ability to derive complex types by extension.

In the XML instance document, you declare the type of an XML element from a set of types that are all derived from the same base type, rather than explicitly declaring the type for the XML element in the XML Schema. The type for the element is defined using the type attribute as shown by the following example XML instance document:

<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns="http://shapesrus.com/example" 
		xmlns:xsd="http://www.w3.org/2001/XMLSchema-instance" xsd:type="circle">
 <color xmlns="">blue</color>
 <diameter xmlns="">10</diameter>  
</shape>

In the preceding XML instance document, the <shape> element is declared as a circle type. The <shape> element in the XML instance document can also be defined as a rectangle type as defined in the following example XML instance document:

<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns="http://shapesrus.com/example" 
		xmlns:xsd="http://www.w3.org/2001/XMLSchema-instance" xsd:type="rectangle">
 <color xmlns="">blue</color>
 <length xmlns="">5</length>
 <width xmlns="">8</width>  
</shape>
In this example, the <shape> element is based on one of the derived types of shapeType base type. The derived types of shapeType are named circle and rectangle, as shown in the following example XML Schema:
When an XML Schema defines an XML element based on derived types, you must specify the derived type (or substitution type) expected for the XML element during run time. For the preceding example XML Schema, you must specify the type of the <shape> element – either circle or rectangle. In Studio, you specify the expected substitution type of an XML element using the Substitute Node With ... menu option:
  • For a variable based on a substitution type - Select the expected type of the XML element by right-clicking the node in the Schema of pane in the Variables tab and by selecting the Substitute Node With ... option from the menu. For more information see Selecting a Substitution Type for Variables.
  • For a node based on substitution type in a mapping pane - Select the expected type of the XML element by right-clicking the node in the Schema of pane in the Variables tab and by selecting the Substitute Node With ... option from the menu, as described in the following procedure.  

In the preceding example XML Schema, the base type called <shapeType> is defined as abstract. An abstract base type cannot be used in the XML instance document to define the type for the element - one of the derived types must be specified instead. In this example, the <shape> element in the XML instance document cannot be declared as shapeType, it must be declared as one of the derived types; either circle or rectangle.

In the preceding example, the base type is defined as abstract but type substitution of derived types based on a base type that is not abstract is also supported. To make the complexType called shapeType not abstract in the example XML Schema, remove the abstract=true attribute as shown in the following XML Schema segment:
<xsd:complexType name="shapeType">
  <xsd:sequence>
    <xsd:element name="color" type="xsd:string"/>
  </xsd:sequence>
 </xsd:complexType>
A WSDL is a specific XML Schema that defines a Web Service. Using type substitution with a WSDL is also supported.

You can specify the substitution type for an expanded occurrence of a recurring destination node. This type substitution of an expanded occurrence is only supported for the recurring destination nodes. Destination nodes are located on the right side of mapping panes.

Attention: Type substitution of complex types is supported in the mapping panes of activities and for variables. However, deriving elements by extension using substitution groups is not supported in the mapping panes of activities or for variables. For more information, see Unsupported XML Schema Features.

Example XML Schema

The example XML Schema used in this topic is provided for reference:
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
           targetNamespace="http://shapesrus.com/example"
           xmlns:sru="http://shapesrus.com/example">
  <xsd:element name="shape" type="sru:shapeType"/>
    <xsd:complexType name="shapeType" abstract="true">
      <xsd:sequence>
         <xsd:element name="color" type="xsd:string"/>
      </xsd:sequence>
    </xsd:complexType>
    <xsd:complexType name="circle">
       <xsd:complexContent>
         <xsd:extension base="sru:shapeType">
         <xsd:sequence>
           <xsd:element name="diameter" type="xsd:integer"/>
         </xsd:sequence>
        </xsd:extension>
  </xsd:complexContent>
  </xsd:complexType>
  <xsd:complexType name="rectangle">
    <xsd:complexContent>
      <xsd:extension base="sru:shapeType">
      <xsd:sequence>
        <xsd:element name="length" type="xsd:integer"/>
        <xsd:element name="width" type="xsd:integer"/>
      </xsd:sequence>
      </xsd:extension>
    </xsd:complexContent>
  </xsd:complexType>
</xsd:schema>



Feedback | Notices


Timestamp icon Last updated: Wednesday, 15 June 2016


http://pic.dhe.ibm.com/infocenter/wci/v7r0m0/topic/com.ibm.wci.doc/map_Selecting_a_Substitution_Type.html