TOC PREV NEXT INDEX


Element Extension


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;
 
 
Generated C++ code:
class TypeName : public BaseType {
 
public:
 
   group type definition..
 
} ;
 


Notes:
1. group in the extension group definition above can be any content model group type (sequence, all, choice, or group).
2. In the case of C, the extension group is pulled out to form the temporary type (TypeName_2). The internals of this type depend on the content group type.
3. In the case of C++, the BaseType is extended to form a derived class. The contents of the extension group are then added directly to the body of 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;
 

In the case of C++, a new class is derived from the ProductType base class:
class EXTERN ShirtType : public ProductType {
 
public:
 
   // tag constants
 
   enum {
 
      T_size = 1,
 
      T_color = 2
 
   } ;
 
   OSUINT16 t;
 
   union {
 
      /* t = 1 */
 
      SizeType *size;
 
      /* t = 2 */
 
      ColorType *color;
 
   } u;
 
   ...
 
} ;
 

In this case, the contents of the extension are generated directly in the derived class. A temporary type is not created.

Copyright © Objective Systems 2002-2008
This document may be distributed in any form, electronic or otherwise, provided that it is distributed in its entirety and that the copyright and this notice are included.

Objective Systems, Inc.

55 Dowlin Forge Road
Exton, Pennsylvania 19341
http://www.obj-sys.com
Phone: (484) 875-9841
Toll-free: (877) 307-6855 (US only)
Fax: (484) 875-9830
info@obj-sys.com

TOC PREV NEXT INDEX