TOC PREV NEXT INDEX


C Example


The following is a common example of a choice construct with a nested sequence. This allows element a or element b or both elements to be present in an XML instance of the type:

	<xsd:complexType name="AOrBOrBothType">
 
		<xsd:choice>
 
			<xsd:sequence>
 
				<xsd:element name="a" type="xsd:string"/>
 
				<xsd:element name="b" type="xsd:string" 
 
					minOccurs="0"/>
 
			</xsd:sequence>
 
			<xsd:element name="b" type="xsd:string"/>
 
		</xsd:choice>
 
	</xsd:complexType>
 

The generated C code for this type is as follows:
typedef struct AOrBOrBothType_1x1 {
 
   struct {
 
      unsigned bPresent : 1;
 
   } m;
 
   OSXMLSTRING a;
 
   OSXMLSTRING b;
 
} AOrBOrBothType_1x1;
 

 
/* choice tag constants */
 
#define T_AOrBOrBothType__seq1			  	1
 
#define T_AOrBOrBothType_b	      2
 

 
typedef struct AOrBOrBothType {
 
   OSUINT16 t;
 
   union {
 
      /* t = 1 */
 
      AOrBOrBothType_1x1 *_seq1;
 
      /* t = 2 */
 
      OSXMLSTRING* b;
 
   } u;
 
} AOrBOrBothType;
 

In this case, XBinder created the type AOrBOrBothType_1x1 to represent the inner sequence. It then added the _seq1 element to the main C type using this type. A user populating the structure would use the _seq1 element to specify element a or both and would use the b element to specify choice b.

Objective Systems, Inc.

102 Pickering Way, Suite #506
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