Substitution Groups
Substitution groups are very similar to choice types. They allow a given base element (refered to as the substitution group head) to be replaced with a different element. The replacement element is designated as being part of the group through the use of the XSD substitutionGroup attribute.
For example, the following element declarations declare a group in which the head element (Publication) would be replaced with either the Book element or Magazine element:
<xsd:element name="Publication" abstract="true" type="PublicationType"/> <xsd:element name="Book" substitutionGroup="Publication" type="BookType"/> <xsd:element name="Magazine" substitutionGroup="Publication" type="MagazineType"/>In these declarations, the types BookType and MagazineType must be derived from the substitution group head type (in this case, PublicationType). This now allows Book or Magazine to be used anywhere where Publication was declared to be used (in fact, the elements in this case must be Book or Magazine because Publication was declared to be abstract and therefore cannot appear in an XML instance).
XBinder generates a special type to hold each of the substitution group alternative elements. This is a C struct type containing an integer tag value (t) that identifies the substitution alternative followed by a union (u) of all of the alternative element types. This is identical to the mapping for the XSD choice type described in the previous section.
The format of the name for the special type is "_<element>SG", where <element> would be replaced with the name of the substitution group head element. In the example above, the generated type name would be "_PublicationSG".
The general mapping is as follows:
1. If the substitution group head element is abstract, then an entry will not be added to the generated type for it. This is because it cannot be used in an XML instance of the type.
2. The choice tag constants (T_TypeName_type) are the identifiers of each of the particular values in the union. The selected value is stored in the t member variable of the generated structure. In the case of C++, the tag values are in the form of an enum construct within the class containing enumerations of the form T_type.
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 RoadExton, 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 |