Derivations

The derivations type is a special type generated by the XBinder compiler that collects all possible alternatives for XSD complexContent types. Its purpose is to allow handling of XML instances in which the type of the content is not known until run-time and is identified through the special xsi:type attribute. For C, it is similar to a CHOICE construct in that it contains a union of all possible alternatives. For C++, a single base element is generated that uses inheritance and polymorphism as the mechanism to identify derived alternatives.

The general mapping is as follows:

XSD type:

   <xsd:complexType name=”TypeName1”>
      <xsd:complexContent>
         <xsd:extension base="BaseType">
            ...
         </xsd:extension>
      </xsd:complexContent>
   </xsd:complexType>

   <xsd:complexType name=”TypeName2”>
      <xsd:complexContent>
         <xsd:extension base="BaseType">
            ...
         </xsd:extension>
      </xsd:complexContent>
   </xsd:complexType>
   ...

Generated C code:

   /* choice tag constants */
   #define T_TypeName_elem1 1
   #define T_TypeName_elem2 2
   ...
   #define T_TypeName_elemN N

   typedef struct BaseType_derivations {
      OSUINT16 t;
      union {
         /* t = 1 */
         Type1 elem1;
         /* t = 2 */
         Type1 elem2;
         ...
         /* t = N */
         TypeN elemN;
      } u;
      const OSUTF8CHAR* _xsiType;
   } TypeName;

Generated C++ code:

   class BaseType_derivations :
   public OSXSDComplexType
   {
      (no content - abstract interface only)
      ...
   } ;