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_1 {
   struct {
      unsigned bPresent : 1;
   } m;
   OSXMLSTRING a;
   OSXMLSTRING b;
} AOrBOrBothType_1;

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

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

In this case, XBinder created the type AOrBOrBothType_1 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.

Copyright © Objective Systems 2002-2007
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