The general mapping for complexContent with an extension element group is as follows:
XSD type:
<xsd:complexType name="TypeName"> <xsd:complexContent> <xsd:extension base="BaseType"> <xsd:group> <xsd:element name="elem1" type="Type1"/> <xsd:element name="elem2" type="Type2"/> ... <xsd:element name="elemN" type="TypeN"/> </xsd:group> </xsd:extension> </xsd:complexContent> </xsd:complexType>
Generated C code:
typedef struct TypeName_2 { group type definition.. } TypeName_2; typedef struct TypeName { BaseType base; TypeName_2 ext; } TypeName;
typedef struct BaseType_derivations { OSUINT16 t; union { /* t = 1 */ struct BaseType *baseType; /* t = 2 */ struct TypeName *typeName; } u; } BaseType_derivations;
Generated C++ code (extended model):
class TypeName_2 : public OSXSDComplexType { group type definition.. } ; class TypeName : public BaseType { public: TypeName_2 _ext; } ;
Generated C++ code (interface model):
class TypeName : public BaseType_derivations { public: group type definition.. } ;
class BaseType_derivations : public OSXSDComplexType { public: BaseType_derivations () {} ... } ;
Notes:
group in the extension group definition above can be any content model group type (sequence, all, choice, or group).
In the case of C and C++ extended, the extension group is pulled out to form the temporary type (TypeName_2). The internals of this type depend on the content group type.
In the case of C++ interface, all content items (attributes and elements) are contained in the derived class.
Example: Extension Elements
The following complexContent type contains a choice of two additional elements that were not defined in the base type (ProductType):
<xsd:complexType name="ShirtType"> <xsd:complexContent> <xsd:extension base="ProductType"> <xsd:choice> <xsd:element name="size" type="SizeType"/> <xsd:element name="color" type="ColorType"/> </xsd:choice> </xsd:extension> </xsd:complexContent> </xsd:complexType>
The following are the C typedefs that are generated for this definition:
#define T_ShirtType_2_size 1 #define T_ShirtType_2_color 2 typedef struct EXTERN ShirtType_2 { OSUINT16 t; union { /* t = 1 */ SizeType size; /* t = 2 */ ColorType color; } u; } ShirtType_2; typedef struct EXTERN ShirtType { ProductType _base; ShirtType_2 _ext; } ShirtType; #define T_ProductType_derivations_productType1 #define T_ProductType_derivations_shirtType2 struct EXTERN ProductType; struct EXTERN ShirtType; typedef struct EXTERN ProductType_derivations { OSUINT16 t; union { /* t = 1 */ struct ProductType *productType; /* t = 2 */ struct ShirtType *shirtType; } u; } ProductType_derivations;
The case of C++ with the extended model is similar:
class ShirtType : public ProductType { public: // tag constants enum { T_size = 1, T_color = 2 } ; /** * ShirtType member variables */ OSUINT16 t; union { /* t = 1 */ SizeType *size; /* t = 2 */ ColorType *color; } u;
In the case of the C++ interface model, all content items are added to the ShirtType class and the class is derived from the ProductType_derivations base class:
class EXTERN ShirtType_2 : public OSXSDComplexType { public: // tag constants enum { T_size = 1, T_color = 2 } ; OSUINT16 t; union { /* t = 1 */ ::SizeType *size; /* t = 2 */ ::ColorType *color; } u; ... } ; class EXTERN ShirtType : public ProductType_derivations { public: ::ProdNumType number; OSXMLStringClass name; ::ShirtType_2 _ext; ... } ; /** * Types derived from this base type: * ProductType * ShirtType */ class EXTERN ProductType_derivations : public OSXSDComplexType { public: (no content).. } ;