Nested Types

It is possible to nest other XSD sequence or choice content model groups within another sequence. For example, it is possible to nest a sequence definition within another sequence definition as follows:

       <xsd:complexType name="A">
          <xsd:sequence>
             <xsd:element name="x" type="xsd:string"/>
             <xsd:sequence minOccurs="0">
                <xsd:element name="y" type="xsd:integer"/>
                <xsd:element name="z" type="xsd:boolean"/>
             </xsd:sequence>
          </xsd:sequence>
       </xsd:complexType>

In this example, the type has three elements – x , y, and z. A nested SEQUENCE is used with the y and z elements to indicate the group is optional.

The XBinder compiler recursively pulls all of the nested content model groups (i.e. the embedded sequence and choice definitions) out of the sequence type to form a series of types that contain only a single level of elements. The names of the newly formed types are of the form BaseTypeName_S where BaseTypeName is the name of the main type and S is the sequential position of the element within the construct.

Note: The format of newly formed type name was changed from XBinder v1.0.x. Previously, the format was BaseTypeName_LxS, where L was the nesting level and S the relative sequence number. This was found to cause ambibuous names in some situations, therefore the format was changed. Users of the older version can still generate names in this form by using the -compat 1.0 command-line switch.

For example, in the definition above, the following two C types are generated to model the XSD type above:

       typedef struct A_2 {
          OSINT32 y;
          OSBOOL z;
       } A_2;

       typedef struct A {
          struct {
             unsigned _seq2Present : 1;
          } m;
          const OSUTF8CHAR* x;
          A_2 _seq2;
       } A;

In this case, XBinder created the type A_2 to represent the inner sequence. It then added the _seq2 element to the main C type using this type. This allows all of the elements in the inner sequence to be managed as a group in the generated code. This is particularly useful if the element group is optional or repeating.

The C++ generated code is similar except that items are in the form of class definitions instead of structures.