Genivia Home Documentation
README.md Source File

updated Mon Oct 26 2026 by Robert van Engelen
 
README.md
Go to the documentation of this file.
1 
2 C and C++ XML Data Bindings {#mainpage}
3 ===========================
4 
5 [TOC]
6 
7 Introduction {#intro}
8 ============
9 
10 This article presents a detailed overview of the gSOAP XML data bindings for C
11 and C++. The XML data bindings for C and C++ are extensively used with gSOAP
12 Web services to serialize C and C++ data in XML as part of the SOAP/XML Web
13 services payloads. Also REST XML with gSOAP relies on XML serialization of C
14 and C++ data via XML data bindings.
15 
16 The major advantage of XML data bindings is that your application data is
17 always **type safe** in C and C++ by binding XML schema types to C/C++ types.
18 So integers in XML are bound to C integers, strings in XML are bound to C or
19 C++ strings, complex types in XML are bound to C structs or C++ classes, and so
20 on. The structured data you create and accept will fit the data model and is
21 **static type safe**. In other words, by leveraging strong typing in C/C++,
22 your XML data meets **XML schema validation requirements** and satisfies **XML
23 interoperability requirements**.
24 
25 In fact, gSOAP data bindings are more powerful than simply representing C/C++
26 data in XML. The gSOAP tools implement true and tested **structure-preserving
27 serialization** of C/C++ data in XML, including the serialization of cyclic
28 graph structures with id-ref XML attributes. The gSOAP tools also generate
29 routines for deep copying and deep deletion of C/C++ data structures to
30 simplify memory management. In addition, C/C++ structures are deserialized
31 into managed memory, managed by the gSOAP `soap` context.
32 
33 At the end of this article two examples are given to illustrate the application
34 of XML data bindings. The first simple example <i>`address.cpp`</i> shows how to use
35 wsdl2h to bind an XML schema to C++. The C++ application reads and writes an
36 XML file into and from a C++ "address book" data structure as a simple example.
37 The C++ data structure is a vector of address objects. The second example
38 <i>`graph.cpp`</i> shows how C++ data can be accurately serialized as a tree,
39 digraph, and cyclic graph in XML. The digraph and cyclic graph serialization
40 rules implement SOAP 1.1/1.2 multi-ref encoding with id-ref attributes to link
41 elements through IDREF XML references, creating a an XML graph with pointers to
42 XML nodes that preserves the structural integrity of the serialized C++ data.
43 
44 These examples demonstrate XML data bindings only for relatively simple data
45 structures and types. The gSOAP tools support more than just these type of
46 structures to serialize in XML. There are practically no limits to the
47 serialization of C and C++ data types in XML.
48 
49 Also the support for XML schema (XSD) components is unlimited. The wsdl2h tool
50 maps schemas to C and C++ using built-in intuitive mapping rules, while
51 allowing the mappings to be customized using a <i>`typemap.dat`</i> file with mapping
52 instructions for wsdl2h.
53 
54 The information in this article is applicable to gSOAP 2.8.26 and greater that
55 support C++11 features. However, C++11 is not required. The material and the
56 examples in this article use plain C and C++, until the point where we
57 introduce C++11 smart pointers and scoped enumerations. While most of the
58 examples in this article are given in C++, the concepts also apply to C with
59 the exception of containers, smart pointers, classes and their methods. None
60 of these exceptions limit the use of the gSOAP tools for C in any way.
61 
62 The data binding concepts described in this article were first envisioned in
63 1999 by Prof. Robert van Engelen at the Florida State University. An
64 implementation was created in 2000, named "stub/skeleton compiler". The first
65 articles on its successor version "gSOAP" appeared in 2002. The principle of
66 mapping XSD components to C/C++ types and vice versa is now widely adopted in
67 systems and programming languages, including Java web services and by C# WCF.
68 
69 We continue to be committed to our goal to empower C/C++ developers with
70 powerful autocoding tools for XML. Our commitment started in the very early
71 days of SOAP by actively participating in
72 [SOAP interoperability testing](http://www.whitemesa.com/interop.htm),
73 participating in the development and testing of the
74 [W3C XML Schema Patterns for Databinding Interoperability](http://www.w3.org/2002/ws/databinding),
75 and continues by contributing to the development of
76 [OASIS open standards](https://www.oasis-open.org) in partnership with leading
77 IT companies in the world.
78 
79 🔝 [Back to table of contents](#)
80 
81 Notational Conventions {#conventions}
82 ======================
83 
84 The typographical conventions used by this document are:
85 
86 * `Courier` denotes C and C++ source code.
87 
88 * <i>`Courier`</i> denotes XML content, JSON content, file and path names, and URIs.
89 
90 * <b>`Courier`</b> denotes HTTP content, text file content, and shell commands with command line options and arguments.
91 
92 The keywords "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", "SHOULD",
93 "SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in this document are to
94 be interpreted as described in RFC-2119.
95 
96 🔝 [Back to table of contents](#)
97 
98 Mapping WSDL and XML schemas to C/C++ {#tocpp}
99 =====================================
100 
101 To convert WSDL and XML schemas (XSD files) to code, we use the wsdl2h command
102 on the command line (or command prompt), after opening a terminal. The wsdl2h
103 command generates the data binding interface code that is saved to a special
104 Web services and data bindings interface header file with extension <i>`.h`</i>
105 that contains the WSDL service declarations and the data binding interface
106 declarations in a familiar C/C++ format:
107 
108  wsdl2h [options] -o file.h ... XSD and WSDL files ...
109 
110 This command converts WSDL and XSD files to C++ (or pure C with
111 <b>`wsdl2h -c`</b>) and saves the data binding interface to a interface header
112 file <i>`file.h`</i> that uses familiar C/C++ syntax extended with `//gsoap`
113 [directives](#directives) and annotations. Notational conventions are used in
114 the data binding interface to declare serializable C/C++ types and functions
115 for Web service operations.
116 
117 The WSDL 1.1/2.0, SOAP 1.1/1.2, and XSD 1.0/1.1 standards are supported by the
118 gSOAP tools. In addition, the most popular WS specifications are also
119 supported, including WS-Addressing, WS-ReliableMessaging, WS-Discovery,
120 WS-Security, WS-Policy, WS-SecurityPolicy, and WS-SecureConversation.
121 
122 This article focusses mainly on XML data bindings. XML data bindings for C/C++
123 bind XML schema types to C/C++ types. So integers in XML are bound to C
124 integers, strings in XML are bound to C or C++ strings, complex types in XML
125 are bound to C structs or C++ classes, and so on.
126 
127 A data binding is dual, meaning supporting a two way direction for development.
128 Either you start with WSDLs and/or XML schemas that are mapped to equivalent
129 C/C++ types, or you start with C/C++ types that are mapped to XSD types.
130 Either way, the end result is that you can serialize C/C++ types in XML such
131 that your XML is an instance of XML schema(s) and is validated against these
132 schema(s).
133 
134 This covers all of the following standard XSD components with their optional
135 attributes and properties:
136 
137 XSD component | attributes and properties
138 -------------- | -------------------------
139 schema | targetNamespace, version, elementFormDefault, attributeFormDefault, defaultAttributes
140 attribute | name, ref, type, use, default, fixed, form, targetNamespace, wsdl:arrayType
141 element | name, ref, type, default, fixed, form, nillable, abstract, substitutionGroup, minOccurs, maxOccurs, targetNamespace
142 simpleType | name
143 complexType | name, abstract, mixed, defaultAttributesApply
144 all | *n/a*
145 choice | minOccurs, maxOccurs
146 sequence | minOccurs, maxOccurs
147 group | name, ref, minOccurs, maxOccurs
148 attributeGroup | name, ref
149 any | minOccurs, maxOccurs
150 anyAttribute | *n/a*
151 
152 And also the following standard XSD directives are covered:
153 
154 directive | description
155 ---------- | -----------
156 import | Imports a schema into the importing schema for referencing
157 include | Include schema component definitions into a schema
158 override | Override by replacing schema component definitions
159 redefine | Extend or restrict schema component definitions
160 annotation | Annotates a component
161 
162 The XSD facets and their mappings to C/C++ are:
163 
164 XSD facet | maps to
165 -------------- | -------
166 enumeration | `enum`
167 simpleContent | class/struct wrapper with `__item` member
168 complexContent | class/struct
169 list | `enum*` bitmask (`enum*` enumerates a bitmask up to 64 bits)
170 extension | class/struct inheritance/extension
171 restriction | `typedef` and class/struct inheritance/redeclaration
172 length | `typedef` with restricted content length annotation
173 minLength | `typedef` with restricted content length annotation
174 maxLength | `typedef` with restricted content length annotation
175 minInclusive | `typedef` with numerical value range restriction annotation
176 maxInclusive | `typedef` with numerical value range restriction annotation
177 minExclusive | `typedef` with numerical value range restriction annotation
178 maxExclusive | `typedef` with numerical value range restriction annotation
179 precision | `typedef` with pattern annotation (pattern used for output, but input is not validated)
180 scale | `typedef` with pattern annotation (pattern used for output, but input is not validated)
181 totalDigits | `typedef` with pattern annotation (pattern used for output, but input is not validated)
182 fractionDigits | `typedef` with pattern annotation (pattern used for output, but input is not validated)
183 pattern | `typedef` with pattern annotation (define `soap::fsvalidate` callback to validate patterns)
184 union | string with union of value
185 
186 All primitive XSD types are supported, including but not limited to the
187 following XSD types:
188 
189 XSD type | maps to
190 ---------------- | -------
191 any/anyType | `_XML` string with literal XML content (or enable DOM with wsdl2h option `-d`)
192 anyURI | string (i.e. `char*`, `wchar_t*`, `std::string`, `std::wstring`)
193 string | string (i.e. `char*`, `wchar_t*`, `std::string`, `std::wstring`)
194 boolean | `bool` (C++) or `enum xsd__boolean` (C)
195 byte | `char` (i.e. `int8_t`)
196 short | `short` (i.e. `int16_t`)
197 int | `int` (i.e. `int32_t`)
198 long | `LONG64` (i.e. `long long` and `int64_t`)
199 unsignedByte | `unsigned char` (i.e. `uint8_t`)
200 unsignedShort | `unsigned short` (i.e. `uint16_t`)
201 unsignedInt | `unsigned int` (i.e. `uint32_t`)
202 unsignedLong | `ULONG64` (i.e. `unsigned long long` and `uint64_t`)
203 float | `float`
204 double | `double`
205 integer | string or `#import "custom/int128.h"` to use 128 bit `xsd__integer`
206 decimal | string or `#import "custom/long_double.h"` to use `long double`
207 precisionDecimal | string
208 duration | string or `#import "custom/duration.h"` to use 64 bit `xsd__duration`
209 dateTime | `time_t` or `#import "custom/struct_tm.h"` to use `struct tm` for `xsd__dateTime`
210 time | string or `#import "custom/long_time.h"` to use 64 bit `xsd__time`
211 date | string or `#import "custom/struct_tm_date.h"` to use `struct tm` for `xsd__date`
212 hexBinary | special class/struct `xsd__hexBinary`
213 base64Binary | special class/struct `xsd__base64Binary`
214 QName | `_QName` string (URI normalization rules are applied)
215 token | string (normalized by collapsing and replacing white space)
216 
217 All other primitive XSD types not listed above are mapped to strings, by
218 wsdl2h generating a `typedef` to string for these types, see also [String
219 types](#toxsd6). For example, <i>`xsd:token`</i> is bound to a C++ or C
220 string:
221 
222 ~~~{.cpp}
223  typedef std::string xsd__token; // C++
224  typedef char *xsd__token; // C (wsdl2h option -c)
225 ~~~
226 
227 This associates a compatible value space to the type with the appropriate XSD
228 type name used by the soapcpp2-generated serializers.
229 
230 It is possible to remap types by adding the appropriate mapping rules to
231 <i>`typemap.dat`</i> as we will explain in more detail in the next section.
232 
233 Imported custom serializers are intended to extend the C/C++ type bindings when
234 the default binding to string is not satisfactory to your taste and if the
235 target platform supports these C/C++ types. To add custom serializers to
236 <i>`typemap.dat`</i> for wsdl2h, see [adding custom serializers](#custom) below.
237 
238 🔝 [Back to table of contents](#)
239 
240 Using typemap.dat to customize data bindings {#typemap}
241 ============================================
242 
243 Use a <i>`typemap.dat`</i> file to redefine namespace prefixes and to customize type
244 bindings for the the generated header files produced by the wsdl2h tool. The
245 <i>`typemap.dat`</i> is the default file processed by wsdl2h. Use <b>`wsdl2h -tfile.dat`</b>
246 option <b>`-tfile.dat`</b> to specify a different mapping file <i>`file.dat`</i>.
247 
248 Declarations in <i>`typemap.dat`</i> can be broken up over multiple lines by
249 continuing on the next line by ending each line to be continued with a
250 backslash <b>`\`</b>. The limit is 4095 characters per line, whether the line is
251 broken up or not.
252 
253 🔝 [Back to table of contents](#)
254 
255 XML namespace bindings {#typemap1}
256 ----------------------
257 
258 The wsdl2h tool generates C/C++ type declarations that use `ns1`, `ns2`, etc.
259 as schema-binding URI prefixes. These default prefixes are generated somewhat
260 arbitrarily for each schema targetNamespace URI, meaning that their ordering
261 may change depending on the WSDL and XSD order of processing with wsdl2h.
262 
263 Therefore, it is **strongly recommended** to declare your own prefix for each
264 schema URI in <i>`typemap.dat`</i> to reduce maintaince effort of your code. This
265 is more robust when anticipating possible changes of the schema(s) and/or the
266 binding URI(s) and/or the tooling algorithms.
267 
268 The first and foremost important thing to do is to define prefix-URI bindings
269 for our C/C++ code by adding the following line(s) to our <i>`typemap.dat`</i> or make
270 a copy of this file and add the line(s) that bind our choice of prefix name to
271 each URI:
272 
273  prefix = "URI"
274 
275 For example, to use `g` as a prefix for the "urn:graph" XML namespace:
276 
277  g = "urn:graph"
278 
279 This produces `g__name` C/C++ type names that are bound to the "urn:graph"
280 schema by association of `g` to the generated C/C++ types.
281 
282 This means that <i>`<g:name xmlns:g="urn:graph">`</i> is parsed as an instance of a
283 `g__name` C/C++ type. Also <i>`<x:name xmlns:x="urn:graph">`</i> parses as an
284 instance of `g__name`, because the prefix <i>`x`</i> has the same URI value
285 <i>`urn:graph`</i>. Prefixes in XML have local scopes (like variables in a block).
286 
287 The first run of wsdl2h will reveal the XML namespace URIs, so you do not need
288 to search WSDLs and XSD files for all of the target namespaces. Just copy them
289 from the generated header file after the first run into <i>`typemap.dat`</i> for
290 editing.
291 
292 @note Only define a namespace prefix once in <i>`typemap.dat`</i>. That is, do not
293 use the same prefix for multiple XML namespace URIs. This is to avoid
294 namespace conflicts that may cause failed builds and failures in XML parsing
295 and XML schema validation.
296 
297 🔝 [Back to table of contents](#)
298 
299 XSD type bindings {#typemap2}
300 -----------------
301 
302 Custom C/C++ type bindings can be declared in <i>`typemap.dat`</i> to associate C/C++
303 types with specific schema types. These type bindings have four parts:
304 
305  prefix__type = declaration | use | ptr-use
306 
307 where
308 
309 - <b>`prefix__type`</b> is the schema type to be customized (the <b>`prefix__type`</b> name
310  uses the common double underscore naming convention);
311 
312 - <b>`declaration`</b> declares the C/C++ type in the wsdl2h-generated header file.
313  This part can be empty if no explicit declaration is needed;
314 
315 - <b>`use`</b> is an optional part that specifies how the C/C++ type is used in the
316  code. When omitted, it is the same as <b>`prefix__type`</b>;
317 
318 - <b>`ptr-use`</b> is an optional part that specifies how the type is used as a pointer
319  type. By default it is the <b>`use`</b> type name with a <b>`*`</b> or C++11
320  <b>`std::shared_ptr<type>`</b> when enabled (see further below). If <b>`use`</b> is already a
321  pointer type by the presence of a <b>`*`</b> in the <b>`use`</b> part, then the default
322  <b>`ptr-use`</b> type is the same as the <b>`use`</b> type (that is, no double
323  pointers <b>`**`</b> will be created in this case).
324 
325 For example, to map <i>`xsd:duration`</i> to a `long long` (`LONG64`) type that holds
326 millisecond duration values, we can use the custom serializer declared in
327 <i>`gsoap/custom/duration.h`</i> by adding the following line to <i>`typemap.dat`</i>:
328 
329  xsd__duration = #import "custom/duration.h"
330 
331 Here, we omitted the second and third parts, because `xsd__duration` is the
332 name that wsdl2h uses for this type in our generated code so we should leave
333 the <b>`use`</b> part unspecified. The third part is omitted to let wsdl2h use
334 `xsd__duration *` for pointers or `std::shared_ptr<xsd__duration>` if smart
335 pointers are enabled.
336 
337 To map <i>`xsd:string`</i> to `wchar_t*` wide strings for C source code output:
338 
339  xsd__string = | wchar_t* | wchar_t*
340 
341 For C++ we can use the `std::wstring` wide string:
342 
343  xsd__string = | std::wstring
344 
345 Note that the first part is empty, because these types do not require a
346 declaration. A <b>`ptr-use`</b> part is also defined for `wchar_t*`, but this
347 is actually needed because the wsdl2h tool recognizes that the <b>`use`</b>
348 part `wchar_t*` is already a pointer. By contrast, when using 8-bit strings,
349 it is recommended to use the `SOAP_C_UTFSTRING` flag to enable UTF-8 formatted
350 strings.
351 
352 When the <b>`ptr-use`</b> part is not specified, it will be auto-generated
353 as pointer `T*` for <b>`use`</b> type `T` or `std::shared_ptr<T>` when
354 the variable `$POINTER = std::shared`, see
355 [the special variables $CONTAINER, $POINTER, $SIZE and $OPTIONAL](#typemap5).
356 
357 The <b>`declaration`</b> part need not be empty, for example if a type must be
358 declared. For example:
359 
360  xsd__string = typedef std::string mystring; | mystring | std::optional<mystring>
361 
362 When a auto-generated <b>`declaration`</b> should be preserved but the
363 <b>`use`</b> or <b>`ptr-use`</b> parts must be redefined, then we use an
364 ellipsis for the <b>`declaration`</b> part:
365 
366  prefix__type = ... | use | ptr-use
367 
368 The <b>`ptr-use`</b> part is also useful to map schema polymorphic types to C
369 types for example, where we need to be able to both handle a base type and its
370 extensions as per schema extensibility. Say we have a base type called
371 <i>`ns:base`</i> that is extended, then we can remap this to a C type that
372 permits referening the extended types via a `void*` as follows:
373 
374  ns__base = ... | int __type_base; void*
375 
376 such that `__type_base` and `void*` will be used to (de)serialize any data
377 type, including base and its derived types. The `__type_base` integer is set
378 to a `SOAP_TYPE_T` value to indicate what type of data the `void*` pointer
379 points to.
380 
381 🔝 [Back to table of contents](#)
382 
383 Custom serializers for XSD types {#custom}
384 --------------------------------
385 
386 In the previous part we saw how a custom serializer is used to bind
387 <i>`xsd:duration`</i> to a `long long` (`LONG64` or `int64_t`) type to store millisecond
388 duration values:
389 
390  xsd__duration = #import "custom/duration.h"
391 
392 The `xsd__duration` type is an alias of `long long` (`LONG64` or `int64_t`).
393 
394 While wsdl2h will use this binding declared in <i>`typemap.dat`</i>
395 automatically, you will also need to compile <i>`gsoap/custom/duration.c`</i>.
396 Each custom serializer has an interface header file to be imported into another
397 interface header file that declares the custom type for soapcpp2 and a
398 serializer implementation file written in C, which should be compiled with the
399 application. You can compile these in C++ (rename files to <i>`.cpp`</i> if
400 needed).
401 
402 A custom serializer is declared in an interface header file for soapcpp2 using
403 `extern typedef`. The typedef name declared is serializable, whereas the
404 type on which it is based is not serializable. This declaration can be
405 combined with `volatile` when the type should not be redeclared, see
406 [volatile classes and structs](#toxsd9-2). For example, the custom serializer
407 for `struct tm` is the type `xsd__datetime` declared as follows in
408 `gsoap/custom/struct_tm.h`:
409 
410 ~~~{.cpp}
411  extern typedef volatile struct tm
412  {
413  int tm_sec; ///< seconds (0 - 60)
414  int tm_min; ///< minutes (0 - 59)
415  int tm_hour; ///< hours (0 - 23)
416  int tm_mday; ///< day of month (1 - 31)
417  int tm_mon; ///< month of year (0 - 11)
418  int tm_year; ///< year - 1900
419  int tm_wday; ///< day of week (Sunday = 0) (NOT USED)
420  int tm_yday; ///< day of year (0 - 365) (NOT USED)
421  int tm_isdst; ///< is summer time in effect?
422  char* tm_zone; ///< abbreviation of timezone (NOT USED)
423  } xsd__dateTime;
424 ~~~
425 
426 Another example is `xsd__duration` as a custom serializer for the C++11 type
427 `std::chrono::nanoseconds`:
428 
429 ~~~{.cpp}
430  extern typedef class std::chrono::nanoseconds xsd__duration;
431 ~~~
432 
433 Next, we present all pre-defined custom serializers that are available to you.
434 
435 🔝 [Back to table of contents](#)
436 
437 ### xsd:integer {#custom-1}
438 
439 The wsdl2h tool maps <i>`xsd:integer`</i> to a string by default. To map <i>`xsd:integer`</i> to
440 the 128 bit big int type `__int128_t`:
441 
442  xsd__integer = #import "custom/int128.h"
443 
444 The `xsd__integer` type is an alias of `__int128_t`.
445 
446 @warning Beware that the <i>`xsd:integer`</i> value space of integers is in principle
447 unbounded and values can be of arbitrary length. A value range fault
448 `SOAP_TYPE` (value exceeds native representation) or `SOAP_LENGTH` (value
449 exceeds range bounds) will be thrown by the deserializer if the value is out of
450 range.
451 
452 Other XSD integer types that are restrictions of <i>`xsd:integer`</i>, are
453 <i>`xsd:nonNegativeInteger`</i> and <i>`xsd:nonPositiveInteger`</i>, which are further restricted
454 by <i>`xsd:positiveInteger`</i> and <i>`xsd:negativeInteger`</i>. To bind these types to
455 `__int128_t` add the following definitions to <i>`typemap.dat`</i>:
456 
457  xsd__nonNegativeInteger = typedef xsd__integer xsd__nonNegativeInteger 0 : ;
458  xsd__nonPositiveInteger = typedef xsd__integer xsd__nonPositiveInteger : 0 ;
459  xsd__positiveInteger = typedef xsd__integer xsd__positiveInteger 1 : ;
460  xsd__negativeInteger = typedef xsd__integer xsd__negativeInteger : -1 ;
461 
462 Or simply uncomment these definitions in <i>`typemap.dat`</i> when you are using the
463 latest gSOAP releases.
464 
465 @note If `__int128_t` 128 bit integers are not supported on your platform and if it
466 is certain that <i>`xsd:integer`</i> values are within 64 bit value bounds for your
467 application's use, then you can map this type to `LONG64`:
468 
469  xsd__integer = typedef LONG64 xsd__integer;
470 
471 @note Again, a value range fault `SOAP_TYPE` or `SOAP_LENGTH` will be thrown by
472 the deserializer if the value is out of range.
473 
474 After running wsdl2h and soapcpp2, compile <i>`gsoap/custom/int128.c`</i> with your project.
475 
476 @see Section [numerical types](#toxsd5).
477 
478 🔝 [Back to table of contents](#)
479 
480 ### xsd:decimal {#custom-2}
481 
482 The wsdl2h tool maps <i>`xsd:decimal`</i> to a string by default. To map <i>`xsd:decimal`</i> to
483 extended precision floating point:
484 
485  xsd__decimal = #import "custom/long_double.h" | long double
486 
487 By contrast to all other custom serializers, this serializer enables `long
488 double` natively without requiring a new binding name (`xsd__decimal` is NOT
489 defined).
490 
491 If your system supports <i>`quadmath.h`</i> quadruple precision floating point
492 `__float128`, you can map <i>`xsd:decimal`</i> to `xsd__decimal` that is an alias of
493 `__float128`:
494 
495  xsd__decimal = #import "custom/float128.h"
496 
497 @warning Beware that <i>`xsd:decimal`</i> is in principle a decimal value with arbitraty
498 lengths. A value range fault `SOAP_TYPE` will be thrown by the deserializer if
499 the value is out of range.
500 
501 In the XML payload the special values <i>`INF`</i>, <i>`-INF`</i>, <i>`NaN`</i>
502 represent plus or minus infinity and not-a-number, respectively.
503 
504 After running wsdl2h and soapcpp2, compile <i>`gsoap/custom/long_double.c`</i> with your
505 project.
506 
507 @see Section [numerical types](#toxsd5).
508 
509 🔝 [Back to table of contents](#)
510 
511 ### xsd:dateTime {#custom-3}
512 
513 The wsdl2h tool maps <i>`xsd:dateTime`</i> to `time_t` by default.
514 
515 The trouble with `time_t` when represented as 32 bit `long` integers is that it
516 is limited to dates between 1970 and 2038. A 64 bit `time_t` is safe to use if
517 the target platform supports it, but lack of 64 bit `time_t` portability may
518 still cause date range issues.
519 
520 For this reason `struct tm` should be used to represent wider date ranges. This
521 custom serializer avoids using date and time information in `time_t`. You get
522 the raw date and time information. You only lose the day of the week
523 information. It is always Sunday (`tm_wday=0`).
524 
525 To map <i>`xsd:dateTime`</i> to `xsd__dateTime` which is an alias of `struct tm`:
526 
527  xsd__dateTime = #import "custom/struct_tm.h"
528 
529 If the limited date range of `time_t` is not a problem but you want to increase
530 the time precision with fractional seconds, then we suggest to map <i>`xsd:dateTime`</i>
531 to `struct timeval`:
532 
533  xsd__dateTime = #import "custom/struct_timeval.h"
534 
535 If the limited date range of `time_t` is not a problem but you want to use the
536 C++11 time point type `std::chrono::system_clock::time_point` (which internally
537 uses `time_t`):
538 
539  xsd__dateTime = #import "custom/chrono_time_point.h"
540 
541 Again, we should make sure that the dates will not exceed the date range when
542 using the default `time_t` binding for <i>`xsd:dateTime`</i> or when binding
543 <i>`xsd:dateTime`</i> to `struct timeval` or to `std::chrono::system_clock::time_point`.
544 These are safe to use in applications that use <i>`xsd:dateTime`</i> to record date
545 stamps within a given window. Otherwise, we recommend the `struct tm` custom
546 serializer.
547 
548 After running wsdl2h and soapcpp2, compile <i>`gsoap/custom/struct_tm.c`</i> with your
549 project.
550 
551 You could even map <i>`xsd:dateTime`</i> to a plain string (use `char*` with C and
552 `std::string` with C++). For example:
553 
554  xsd__dateTime = | char*
555 
556 @see Section [date and time types](#toxsd7).
557 
558 🔝 [Back to table of contents](#)
559 
560 ### xsd:date {#custom-4}
561 
562 The wsdl2h tool maps <i>`xsd:date`</i> to a string by default. We can map <i>`xsd:date`</i> to
563 `struct tm`:
564 
565  xsd__date = #import "custom/struct_tm_date.h"
566 
567 The `xsd__date` type is an alias of `struct tm`. The serializer ignores the
568 time part and the deserializer only populates the date part of the struct,
569 setting the time to 00:00:00. There is no unreasonable limit on the date range
570 because the year field is stored as an integer (`int`).
571 
572 After running wsdl2h and soapcpp2, compile <i>`gsoap/custom/struct_tm_date.c`</i> with your
573 project.
574 
575 @see Section [date and time types](#toxsd7).
576 
577 🔝 [Back to table of contents](#)
578 
579 ### xsd:time {#custom-5}
580 
581 The wsdl2h tool maps <i>`xsd:time`</i> to a string by default. We can map <i>`xsd:time`</i> to
582 an `unsigned long long` (`ULONG64` or `uint64_t`) integer with microsecond time
583 precision:
584 
585  xsd__time = #import "custom/long_time.h"
586 
587 This type represents 00:00:00.000000 to 23:59:59.999999, from `0` to an upper
588 bound of `86399999999`. A microsecond resolution means that a 1 second
589 increment requires an increment of 1000000 in the integer value. The serializer
590 adds a UTC time zone.
591 
592 After running wsdl2h and soapcpp2, compile <i>`gsoap/custom/long_time.c`</i> with your
593 project.
594 
595 @see Section [date and time types](#toxsd7).
596 
597 🔝 [Back to table of contents](#)
598 
599 ### xsd:duration {#custom-6}
600 
601 The wsdl2h tool maps <i>`xsd:duration`</i> to a string by default, unless <i>`xsd:duration`</i>
602 is mapped to a `long long` (`LONG64` or `int64_t`) type with with millisecond
603 (ms) time duration precision:
604 
605  xsd__duration = #import "custom/duration.h"
606 
607 The `xsd__duration` type is a 64 bit signed integer that can represent
608 106,751,991,167 days forwards (positive) and backwards (negative) in time in
609 increments of 1 ms (1/1000 of a second).
610 
611 Rescaling of the duration value by may be needed when adding the duration value
612 to a `time_t` value, because `time_t` may or may not have a seconds resolution,
613 depending on the platform and possible changes to `time_t`.
614 
615 Rescaling is done automatically when you add a C++11 `std::chrono::nanoseconds`
616 value to a `std::chrono::system_clock::time_point` value. To use
617 `std::chrono::nanoseconds` as <i>`xsd:duration`</i>:
618 
619  xsd__duration = #import "custom/chrono_duration.h"
620 
621 This type can represent 384,307,168 days (2^63 nanoseconds) forwards and
622 backwards in time in increments of 1 ns (1/1,000,000,000 of a second).
623 
624 Certain observations with respect to receiving durations in years and months
625 apply to both of these serializer decoders for <i>`xsd:duration`</i>.
626 
627 After running wsdl2h and soapcpp2, compile <i>`gsoap/custom/duration.c`</i> with your
628 project.
629 
630 @see Section [time duration types](#toxsd8).
631 
632 🔝 [Back to table of contents](#)
633 
634 Custom Qt serializers for XSD types {#qt}
635 -----------------------------------
636 
637 The gSOAP distribution includes several custom serializers for Qt types. Also
638 Qt container classes are supported, see
639 [the special variables $CONTAINER, $POINTER, $SIZE and $OPTIONAL](#typemap5).
640 
641 This feature requires gSOAP 2.8.34 or higher and Qt 4.8 or higher.
642 
643 Each Qt custom serializer has an interface header file for soapcpp2 and a C++
644 implementation file to be compiled with your project.
645 
646 Other Qt primitive types that are Qt `typedef`s of C/C++ types do not require a
647 custom serializer.
648 
649 🔝 [Back to table of contents](#)
650 
651 ### xsd:string {#qt-1}
652 
653 To use Qt strings instead of C++ strings, add the following definition to
654 <i>`typemap.dat`</i>:
655 
656  xsd__string = #import "custom/qstring.h"
657 
658 After running wsdl2h and soapcpp2, compile <i>`gsoap/custom/qstring.cpp`</i> with your
659 project.
660 
661 🔝 [Back to table of contents](#)
662 
663 ### xsd:base64Binary {#qt-2}
664 
665 To use Qt byte arrays for <i>`xsd:base64Binary`</i> instead of the
666 `xsd__base64Binary` class, add the following definition to <i>`typemap.dat`</i>:
667 
668  xsd__base64Binary = #import "custom/qbytearray_base64.h"
669 
670 After running wsdl2h and soapcpp2, compile <i>`gsoap/custom/qbytearray_base64.cpp`</i> with
671 your project.
672 
673 🔝 [Back to table of contents](#)
674 
675 ### xsd:hexBinary {#qt-3}
676 
677 To use Qt byte arrays for <i>`xsd:hexBinary`</i> instead of the `xsd__base64Binary`
678 class, add the following definition to <i>`typemap.dat`</i>:
679 
680  xsd__hexBinary = #import "custom/qbytearray_hex.h"
681 
682 After running wsdl2h and soapcpp2, compile <i>`gsoap/custom/qbytearray_hex.cpp`</i> with
683 your project.
684 
685 🔝 [Back to table of contents](#)
686 
687 ### xsd:dateTime {#qt-4}
688 
689 To use Qt QDateTime for <i>`xsd:dateTime`</i>, add the following definition to
690 <i>`typemap.dat`</i>:
691 
692  xsd__dateTime = #import "custom/datetime.h"
693 
694 After running wsdl2h and soapcpp2, compile <i>`gsoap/custom/qdatetime.cpp`</i> with
695 your project.
696 
697 🔝 [Back to table of contents](#)
698 
699 ### xsd:date {#qt-5}
700 
701 To use Qt QDate for <i>`xsd:date`</i>, add the following definition to
702 <i>`typemap.dat`</i>:
703 
704  xsd__date = #import "custom/qdate.h"
705 
706 After running wsdl2h and soapcpp2, compile <i>`gsoap/custom/qdate.cpp`</i> with your
707 project.
708 
709 🔝 [Back to table of contents](#)
710 
711 ### xsd:time {#qt-6}
712 
713 To use Qt QDate for <i>`xsd:time`</i>, add the following definition to
714 <i>`typemap.dat`</i>:
715 
716  xsd__time = #import "custom/qtime.h"
717 
718 After running wsdl2h and soapcpp2, compile <i>`gsoap/custom/qtime.cpp`</i> with your
719 project.
720 
721 🔝 [Back to table of contents](#)
722 
723 Class/struct member additions {#typemap3}
724 -----------------------------
725 
726 All generated classes and structs can be augmented with additional
727 members such as methods, constructors and destructors, and private members:
728 
729  prefix__type = $ member-declaration
730 
731 For example, we can add method declarations and private members to a class, say
732 `ns__record` as follows:
733 
734  ns__record = $ ns__record(const ns__record &); // copy constructor
735  ns__record = $ void print(); // a print method
736  ns__record = $ private: int status; // a private member
737 
738 Method declarations cannot include any code, because soapcpp2's input permits
739 only type declarations, not code.
740 
741 🔝 [Back to table of contents](#)
742 
743 Replacing XSD types by equivalent alternatives {#typemap4}
744 ----------------------------------------------
745 
746 Type replacements can be given to replace one type entirely with another given
747 type:
748 
749  prefix__type1 == prefix__type2
750 
751 This replaces all `prefix__type1` by `prefix__type2` in the wsdl2h output.
752 
753 @warning Do not agressively replace types, because this can cause XML schema
754 validation to fail when a value-type mismatch is encountered in the XML input.
755 Therefore, only replace similar types with other similar types that are wider
756 (e.g. `short` by `int` and `float` by `double`).
757 
758 🔝 [Back to table of contents](#)
759 
760 The special variables $CONTAINER, $POINTER, $SIZE and $OPTIONAL {#typemap5}
761 ---------------------------------------------------------------
762 
763 The <i>`typemap.dat`</i> <b>`$CONTAINER`</b> variable defines the container type to use in
764 the wsdl2h-generated declarations for C++, which is `std::vector` by default.
765 For example, to use `std::list` as the container in the wsdl2h-generated
766 declarations we add the following line to <i>`typemap.dat`</i>:
767 
768  $CONTAINER = std::list
769 
770 Also a Qt container can be used instead of the default `std::vector`, for
771 example `QVector`:
772 
773  [
774  #include <QVector>
775  ]
776  $CONTAINER = QVector
777 
778 To remove containers, use <b>`wsdl2h -s`</b>. This also removes `std::string`,
779 but you can re-introduce `std::string` with
780 <b>`xsd__string = | std::string`</b> in <i>`typemap.dat`</i>.
781 
782 The <i>`typemap.dat`</i> <b>`$POINTER`</b> variable defines the smart pointer to use in the
783 wsdl2h-generated declarations for C++, which replaces the use of `*` pointers.
784 For example:
785 
786  $POINTER = std::shared_ptr
787 
788 Not all pointers in the generated output are replaced by smart pointers by
789 wsdl2h, such as pointers as union members and pointers as struct/class members
790 that point to arrays of values.
791 
792 @note The standard smart pointer `std::shared_ptr` is generally safe to use.
793 Other smart pointers such as `std::unique_ptr` and `std::auto_ptr` may cause
794 compile-time errors when classes have smart pointer members but no copy
795 constructor (a default copy constructor). A copy constructor is required for
796 non-shared smart pointer copying or swapping.
797 
798 Alternatives to `std::shared_ptr` of the form `NAMESPACE::shared_ptr` can be
799 assigned to <b>`$POINTER`</b> when the namespace `NAMESPACE` also implements
800 `NAMESPACE::make_shared` and when the shared pointer class provides `reset()`
801 and`get()` methods and the dereference operator. For example Boost
802 `boost::shared_ptr`:
803 
804  [
805  #include <boost/shared_ptr.hpp>
806  ]
807  $POINTER = boost::shared_ptr
808 
809 The user-defined content between <b>`[`</b> and <b>`]`</b> ensures that we include the Boost
810 header files that are needed to support `boost::shared_ptr` and
811 `boost::make_shared`.
812 
813 The variable <b>`$SIZE`</b> defines the type of array sizes, which is `int` by
814 default. For example, to change array size types to `size_t`:
815 
816  $SIZE = size_t
817 
818 Permissible types are `int` and `size_t`. This variable does not affect the
819 size of dynamic arrays, `xsd__hexBinary` and `xsd__base64Binary` types, which
820 is always `int`.
821 
822 When C++17 is enabled with wsdl2h and soapcpp2 option <b>`-c++17`</b>, you can
823 also semi-automatically enable `std::optional` declarations with optional class
824 and structure member variables. This means that `std::optional` is used
825 instead of a (smart) pointer to make a member optional.
826 
827 To enable `std::optional` with member variables that are primitive types,
828 `typedef`, and `enum` automatically:
829 
830  $OPTIONAL = std::optional
831 
832 Local unnamed simpleType restrictions may not adopt the specified optional type
833 and still use pointers instead. This limitation may be lifted in a future
834 release.
835 
836 🔝 [Back to table of contents](#)
837 
838 User-defined content {#typemap6}
839 --------------------
840 
841 Any other content to be generated by wsdl2h can be included in <i>`typemap.dat`</i> by
842 enclosing it within brackets <b>`[`</b> and <b>`]`</b> anywhere in the <i>`typemap.dat`</i> file.
843 Each of the two brackets must appear at the start of a new line.
844 
845 For example, we can add an `#import "wsa5.h"` to the wsdl2h-generated output as
846 follows:
847 
848  [
849  #import "import/wsa5.h"
850  ]
851 
852 which emits the `#import "import/wsa5.h"` literally at the start of the
853 wsdl2h-generated header file.
854 
855 🔝 [Back to table of contents](#)
856 
857 Mapping C/C++ to XML schema {#toxsd}
858 ===========================
859 
860 The soapcpp2 command generates the data binding implementation code from a data
861 binding interface <i>`file.h`</i>:
862 
863  soapcpp2 [options] file.h
864 
865 where <i>`file.h`</i> is a interface header file that declares the XML data
866 binding interface. The <i>`file.h`</i> is typically generated by wsdl2h, but
867 you can also declare one yourself. If so, add `//gsoap`
868 [directives](#directives) and declare in this file all our C/C++ types you want
869 to serialize in XML.
870 
871 You can also declare functions that will be converted to Web service operations
872 by soapcpp2. Global function declarations define service operations, which are
873 of the form:
874 
875 ~~~{.cpp}
876  int prefix__func(arg1, arg2, ..., argn, result);
877 ~~~
878 
879 where `arg1`, `arg2`, ..., `argn` are formal argument declarations of the input
880 and `result` is a formal argument for the output, which must be a pointer or
881 reference to the result object to be populated. More information on declaring
882 and implementing service operation functions can be found in the
883 [gSOAP user guide.](../../guide/html/index.html)
884 
885 🔝 [Back to table of contents](#)
886 
887 Overview of serializable C/C++ types {#toxsd1}
888 ------------------------------------
889 
890 The following C/C++ types are supported by soapcpp2 and mapped to XSD types
891 and constructs. See the subsections below for more details or follow the links.
892 
893 🔝 [Back to table of contents](#)
894 
895 ### List of Boolean types
896 
897 Boolean Type | Notes
898 ----------------------------- | -----
899 `bool` | C++ bool
900 `enum xsd__boolean` | C alternative to C++ `bool` with `false_` and `true_`
901 
902 @see Section [C++ bool and C alternative](#toxsd3).
903 
904 🔝 [Back to table of contents](#)
905 
906 ### List of enumeration and bitmask types
907 
908 Enumeration Type | Notes
909 ----------------------------- | -----
910 `enum` | enumeration
911 `enum class` | C++11 scoped enumeration, requires `soapcpp2 -c++11`
912 `enum*` | a bitmask that enumerates values 1, 2, 4, 8, ...
913 `enum* class` | C++11 scoped enumeration bitmask, requires `soapcpp2 -c++11`
914 
915 @see Section [enumerations and bitmasks](#toxsd4).
916 
917 🔝 [Back to table of contents](#)
918 
919 ### List of numerical types
920 
921 Numerical Type | Notes
922 ----------------------------- | -----
923 `char` | byte
924 `short` | 16 bit integer
925 `int` | 32 bit integer
926 `long` | 32 bit integer
927 `LONG64` | 64 bit integer
928 `xsd__integer` | 128 bit integer, use `#import "custom/int128.h"`
929 `long long` | same as `LONG64`
930 `unsigned char` | unsigned byte
931 `unsigned short` | unsigned 16 bit integer
932 `unsigned int` | unsigned 32 bit integer
933 `unsigned long` | unsigned 32 bit integer
934 `ULONG64` | unsigned 64 bit integer
935 `unsigned long long` | same as `ULONG64`
936 `int8_t` | same as `char`
937 `int16_t` | same as `short`
938 `int32_t` | same as `int`
939 `int64_t` | same as `LONG64`
940 `uint8_t` | same as `unsigned char`
941 `uint16_t` | same as `unsigned short`
942 `uint32_t` | same as `unsigned int`
943 `uint64_t` | same as `ULONG64`
944 `size_t` | transient type (not serializable)
945 `float` | 32 bit float
946 `double` | 64 bit float
947 `long double` | extended precision float, use `#import "custom/long_double.h"`
948 `xsd__decimal` | `quadmath.h` library 128 bit quadruple precision float, use `#import "custom/float128.h"`
949 `typedef` | declares a type name, with optional value range and string length bounds
950 
951 @see Section [numerical types](#toxsd5).
952 
953 🔝 [Back to table of contents](#)
954 
955 ### List of string types
956 
957 String Type | Notes
958 ----------------------------- | -----
959 `char*` | string (may contain UTF-8 with flag `SOAP_C_UTFSTRING`)
960 `wchar_t*` | wide string
961 `std::string` | C++ string (may contain UTF-8 with flag `SOAP_C_UTFSTRING`)
962 `std::wstring` | C++ wide string
963 `char[N]` | fixed-size string, requires `soapcpp2 -b`
964 `_QName` | normalized QName content
965 `_XML` | literal XML string content with wide characters in UTF-8
966 `typedef` | declares a new string type name, may also restrict string length
967 
968 @see Section [string types](#toxsd6).
969 
970 🔝 [Back to table of contents](#)
971 
972 ### List of date and time types
973 
974 Date and Time Type | Notes
975 --------------------------------------- | -----
976 `time_t` | date and time point since epoch
977 `struct tm` | date and time point, use `#import "custom/struct_tm.h"`
978 `struct tm` | date point, use `#import "custom/struct_tm_date.h"`
979 `struct timeval` | date and time point, use `#import "custom/struct_timeval.h"`
980 `unsigned long long` | time point in microseconds, use `#import "custom/long_time.h"`
981 `std::chrono::system_clock::time_point` | date and time point, use `#import "custom/chrono_time_point.h"`
982 
983 @see Section [date and time types](#toxsd7).
984 
985 🔝 [Back to table of contents](#)
986 
987 ### List of time duration types
988 
989 Time Duration Type | Notes
990 ----------------------------- | -----
991 `long long` | duration in milliseconds, use `#import "custom/duration.h"`
992 `std::chrono::nanoseconds` | duration in nanoseconds, use `#import "custom/chrono_duration.h"`
993 
994 @see Section [time duration types](#toxsd8).
995 
996 🔝 [Back to table of contents](#)
997 
998 ### List of classes, structs, unions, pointers, containers, and arrays
999 
1000 Classes, Structs, and Members | Notes
1001 ----------------------------- | -----
1002 `class` | C++ class with single inheritance only
1003 `struct` | C struct or C++ struct without inheritance
1004 `std::shared_ptr<T>` | C++11 smart shared pointer
1005 `std::unique_ptr<T>` | C++11 smart pointer
1006 `std::auto_ptr<T>` | C++ smart pointer
1007 `std::deque<T>` | use `#import "import/stldeque.h"`
1008 `std::list<T>` | use `#import "import/stllist.h"`
1009 `std::vector<T>` | use `#import "import/stlvector.h"`
1010 `std::set<T>` | use `#import "import/stlset.h"`
1011 `template<T> class` | a container with `begin()`, `end()`, `size()`, `clear()`, and `insert()` methods
1012 `T*` | pointer to data of type `T`
1013 `T*` | as a class or struct member: points to data of type `T` or array of `T` with member `__size`
1014 `T[N]` | as a class or struct member: fixed-size array of type `T`
1015 `union` | as a class or struct member: requires a variant selector member `__union`
1016 `void*` | as a class or struct member: requires a `__type` member to indicate the type of object pointed to
1017 
1018 @see Section [classes and structs](#toxsd9).
1019 
1020 🔝 [Back to table of contents](#)
1021 
1022 ### List of special classes and structs
1023 
1024 Special Classes and Structs | Notes
1025 ----------------------------- | -----
1026 Special Array class/struct | single and multidimensional SOAP Arrays
1027 Special Wrapper class/struct | complexTypes with simpleContent, wraps `__item` member
1028 `xsd__hexBinary` | binary content
1029 `xsd__base64Binary` | binary content and optional DIME/MIME/MTOM attachments
1030 `xsd__anyType` | DOM elements, use `#import "dom.h"`
1031 `@xsd__anyAttribute` | DOM attributes, use `#import "dom.h"`
1032 
1033 @see Section [special classes and structs](#toxsd10).
1034 
1035 🔝 [Back to table of contents](#)
1036 
1037 Colon notation versus name prefixing with XML tag name translation {#toxsd2}
1038 ------------------------------------------------------------------
1039 
1040 To bind C/C++ type names to XSD types, a simple form of name prefixing is used
1041 by the gSOAP tools by prepending the XML namespace prefix to the C/C++ type
1042 name with a pair of undescrores. This also ensures that name clashes cannot
1043 occur when multiple WSDL and XSD files are converted to C/C++. Also, C++
1044 namespaces are not sufficiently rich to capture XML schema namespaces
1045 accurately, for example when class members are associated with schema elements
1046 defined in another XML namespace and thus the XML namespace scope of the
1047 member's name is relevant, not just its type.
1048 
1049 However, from a C/C++ centric point of view this can be cumbersome. Therefore,
1050 colon notation is an alternative to physically augmenting C/C++ names with
1051 prefixes.
1052 
1053 For example, the following class uses colon notation to bind the `record` class
1054 to the <i>`urn:types`</i> schema:
1055 
1056 ~~~{.cpp}
1057  //gsoap ns schema namespace: urn:types
1058  class ns:record // binding 'ns:' to a type name
1059  {
1060  public:
1061  std::string name;
1062  uint64_t SSN;
1063  ns:record *spouse; // using 'ns:' with the type name
1064  ns:record(); // using 'ns:' here too
1065  ~ns:record(); // and here
1066  };
1067 ~~~
1068 
1069 The colon notation is stripped away by soapcpp2 when generating the data
1070 binding implementation code for our project. So the final code just uses
1071 `record` to identify this class and its constructor/destructor.
1072 
1073 When using colon notation make sure to be consistent and not use colon notation
1074 mixed with prefixed forms. The qualified name `ns:record` differs from
1075 `ns__record`, because `ns:record` is compiled to an unqualified `record` name
1076 in the source code output by the soapcpp2 tool.
1077 
1078 Colon notation also facilitates overruling the elementFormDefault and
1079 attributeFormDefault declaration that is applied to local elements and
1080 attributes, when declared as members of classes, structs, and unions. With
1081 colon notation for class, struct and union members, the corresponding XML
1082 elements and attributes are selectively qualified with the specified prefix or
1083 unqualified when the prefix is omitted in front of the colon. For more
1084 details, see [qualified and unqualified members](#toxsd9-6).
1085 
1086 A C/C++ identifier name (a type name, member name, function name, or parameter
1087 name) is translated to an XML tag name by the following rules:
1088 
1089 - Two leading underscores indicates that the identifier name has no XML tag
1090  name, i.e. this name is not visible in XML and is not translated.
1091 
1092 - A leading underscore is removed, but the underscore indicates that: **a**) a
1093  struct/class member name or parameter name has a wildcard XML tag name (i.e.
1094  matches any XML tag), or **b**) a type name that has a
1095  [document root element definition](#toxsd9-7).
1096 
1097 - Trailing underscores are removed (i.e. trailing underscores can be used to
1098  avoid name clashes with keywords).
1099 
1100 - Two underscores `__` in a name represent the namespace prefix of a name.
1101 
1102 - A colon (`:`) within a name represent the namespace prefix of a name that is
1103  present in XML, but this prefix is not present in the generated C/C++ code.
1104 
1105 - A leading colon (`:`) before a name makes the name unqualified in XML.
1106 
1107 - Underscores within names are translated to hyphens (hyphens are more common
1108  in XML tag names).
1109 
1110 - `_USCORE` is translated to an underscore in the translated XML tag name.
1111 
1112 - `_DOT` is translated to a dot (<i>`.`</i>) in the translated XML tag name.
1113 
1114 - `_xHHHH` is translated to the Unicode character with code point HHHH (hex).
1115 
1116 - C++11 Unicode identifier name characters in UTF-8 are translated as-is.
1117 
1118 For example, the C/C++ identifier name `s_a__my_way` is represented in XML
1119 by the tag name <i>`s-a:my-way`</i> by translating the prefix `s_a` and the
1120 local name `my_way`. With colon notation, the colon-qualified C/C++ identifier
1121 name `s_a:my_way` is also represented in XML by the same tag name
1122 <i>`s-a:my-way`</i>, but the generated C/C++ source code defines and uses the
1123 local name `my_way` only.
1124 
1125 Struct/class member and parameter name translation can be overruled by using
1126 [backtick XML tags](#toxsd9-5-1) (with gSOAP 2.8.30 and greater).
1127 
1128 🔝 [Back to table of contents](#)
1129 
1130 C++ bool and C alternative {#toxsd3}
1131 --------------------------
1132 
1133 The C++ `bool` type is bound to built-in XSD type <i>`xsd:boolean`</i>.
1134 
1135 The C alternative is to define an enumeration:
1136 
1137 ~~~{.cpp}
1138  enum xsd__boolean { false_, true_ };
1139 ~~~
1140 
1141 or by defining an enumeration in C with pseudo-scoped enumeration constants:
1142 
1143 ~~~{.cpp}
1144  enum xsd__boolean { xsd__boolean__false, xsd__boolean__true };
1145 ~~~
1146 
1147 The XML value space of these types is <i>`false`</i> and <i>`true`</i>, but also accepted
1148 are <i>`0`</i> and <i>`1`</i> values for <i>`false`</i> and <i>`true`</i>, respectively.
1149 
1150 To prevent name clashes, `false_` and `true_` have a trailing underscore in
1151 their `enum` symbols. Trailing underscores are removed from the XML value space.
1152 
1153 🔝 [Back to table of contents](#)
1154 
1155 Enumerations and bitmasks {#toxsd4}
1156 -------------------------
1157 
1158 Enumerations are mapped to XSD simpleType enumeration restrictions of
1159 <i>`xsd:string`</i>, <i>`xsd:QName`</i>, and <i>`xsd:long`</i>.
1160 
1161 Consider for example:
1162 
1163 ~~~{.cpp}
1164  enum ns__Color { RED, WHITE, BLUE };
1165 ~~~
1166 
1167 which maps to a simpleType restriction of <i>`xsd:string`</i> in the soapcpp2-generated
1168 schema:
1169 
1170 <div class="alt">
1171 ~~~{.xml}
1172  <simpleType name="Color">
1173  <restriction base="xsd:string">
1174  <enumeration value="RED"/>
1175  <enumeration value="WHITE"/>
1176  <enumeration value="BLUE"/>
1177  </restriction>
1178  </simpleType>
1179 ~~~
1180 </div>
1181 
1182 Enumeration name constants can be pseudo-scoped to prevent name clashes,
1183 because enumeration name constants have a global scope in C and C++:
1184 
1185 ~~~{.cpp}
1186  enum ns__Color { ns__Color__RED, ns__Color__WHITE, ns__Color__BLUE };
1187 ~~~
1188 
1189 You can also use C++11 scoped enumerations to prevent name clashes:
1190 
1191 ~~~{.cpp}
1192  enum class ns__Color : int { RED, WHITE, BLUE };
1193 ~~~
1194 
1195 Here, the enumeration class base type `: int` is optional. In place of `int`
1196 in the example above, we can also use `int8_t`, `int16_t`, `int32_t`, or
1197 `int64_t`.
1198 
1199 The XML value space of the enumertions defined above is <i>`RED`</i>, <i>`WHITE`</i>, and
1200 <i>`BLUE`</i>.
1201 
1202 Prefix-qualified enumeration name constants are mapped to simpleType
1203 restrictions of <i>`xsd:QName`</i>, for example:
1204 
1205 ~~~{.cpp}
1206  enum ns__types { xsd__int, xsd__float };
1207 ~~~
1208 
1209 which maps to a simpleType restriction of <i>`xsd:QName`</i> in the soapcpp2-generated
1210 schema:
1211 
1212 <div class="alt">
1213 ~~~{.xml}
1214  <simpleType name="types">
1215  <restriction base="xsd:QName">
1216  <enumeration value="xsd:int"/>
1217  <enumeration value="xsd:float"/>
1218  </restriction>
1219  </simpleType>
1220 ~~~
1221 </div>
1222 
1223 Enumeration name constants can be pseudo-numeric as follows:
1224 
1225 ~~~{.cpp}
1226  enum ns__Primes { _3 = 3, _5 = 5, _7 = 7, _11 = 11 };
1227 ~~~
1228 
1229 which maps to a simpleType restriction of <i>`xsd:long`</i>:
1230 
1231 <div class="alt">
1232 ~~~{.xml}
1233  <simpleType name="Color">
1234  <restriction base="xsd:long">
1235  <enumeration value="3"/>
1236  <enumeration value="5"/>
1237  <enumeration value="7"/>
1238  <enumeration value="11"/>
1239  </restriction>
1240  </simpleType>
1241 ~~~
1242 </div>
1243 
1244 The XML value space of this type is <i>`3`</i>, <i>`5`</i>, <i>`7`</i>, and <i>`11`</i>.
1245 
1246 Besides (pseudo-) scoped enumerations, another way to prevent name clashes
1247 accross enumerations is to start an enumeration name constant with one
1248 underscore or followed it by any number of underscores, which makes it
1249 unique. The leading and trailing underscores are removed from the XML value
1250 space.
1251 
1252 ~~~{.cpp}
1253  enum ns__ABC { A, B, C };
1254  enum ns__BA { B, A }; // BAD: B = 1 but B is already defined as 2
1255  enum ns__BA_ { B_, A_ }; // OK
1256 ~~~
1257 
1258 The gSOAP soapcpp2 tool permits reusing enumeration name constants across
1259 (non-scoped) enumerations as long as these values are assigned the same
1260 constant. Therefore, the following is permitted:
1261 
1262 ~~~{.cpp}
1263  enum ns__Primes { _3 = 3, _5 = 5, _7 = 7, _11 = 11 };
1264  enum ns__Throws { _1 = 1, _2 = 2, _3 = 3, _4 = 4, _5 = 5, _6 = 6 };
1265 ~~~
1266 
1267 A bitmask type is an `enum*` "product enumeration" with a geometric,
1268 power-of-two sequence of values assigned to the enumeration constants:
1269 
1270 ~~~{.cpp}
1271  enum* ns__Options { SSL3, TLS10, TLS11, TLS12, TLS13 };
1272 ~~~
1273 
1274 where the product enum assigns 1 to `SSL3`, 2 to `TLS10`, 4 to `TLS11`, 8
1275 to `TLS12`, and 16 to `TLS13`, which allows these enumeration constants to be
1276 used in composing bitmasks with `|` (bitwise or) `&` (bitwise and), and `~`
1277 (bitwise not):
1278 
1279 ~~~{.cpp}
1280  enum ns__Options options = (enum ns__Options)(SSL3 | TLS10 | TLS11 | TLS12 | TLS13);
1281  if (options & SSL3) // if SSL3 is an option, warn and remove from options
1282  {
1283  warning();
1284  options &= ~SSL3;
1285  }
1286 ~~~
1287 
1288 The bitmask type maps to a simpleType list restriction of <i>`xsd:string`</i> in the
1289 soapcpp2-generated XML schema:
1290 
1291 <div class="alt">
1292 ~~~{.xml}
1293  <simpleType name="Options">
1294  <list>
1295  <restriction base="xsd:string">
1296  <enumeration value="SSL3"/>
1297  <enumeration value="TLS10"/>
1298  <enumeration value="TLS11"/>
1299  <enumeration value="TLS12"/>
1300  <enumeration value="TLS13"/>
1301  </restriction>
1302  </list>
1303  </simpleType>
1304 ~~~
1305 </div>
1306 
1307 The XML value space of this type consists of all 16 possible subsets of the
1308 four values, represented by an XML string with space-separated values. For
1309 example, the bitmask `TLS10 | TLS11 | TLS12` equals 14 and is represented by
1310 the XML text <i>`TLS10 TLS11 TLS12`</i>.
1311 
1312 You can also use C++11 scoped enumerations with bitmasks using `enum*` product
1313 enumerations:
1314 
1315 ~~~{.cpp}
1316  enum* class ns__Options { SSL3, TLS10, TLS11, TLS12, TLS13 };
1317 ~~~
1318 
1319 The base type of a scoped enumeration bitmask, when explicitly given, is
1320 ignored. The base type is either `int` or `int64_t`, depending on the number
1321 of constants enumerated in the bitmask.
1322 
1323 To convert `enum` name constants and bitmasks to a string, we use the
1324 auto-generated function for enum `T`:
1325 
1326 ~~~{.cpp}
1327  const char *soap_T2s(struct soap*, enum T val)
1328 ~~~
1329 
1330 The string returned is stored in an internal buffer of the current `soap`
1331 context, so you should copy it to keep it from being overwritten. For example,
1332 use `char *soap_strdup(struct soap*, const char*)`.
1333 
1334 To convert a string to an `enum` constant or bitmask, we use the auto-generated
1335 function
1336 
1337 ~~~{.cpp}
1338  int soap_s2T(struct soap*, const char *str, enum T *val)
1339 ~~~
1340 
1341 This function takes the name (or names, space-separated for bitmasks) of
1342 the enumeration constant in a string `str`. Names should be given without the
1343 pseudo-scope prefix and without trailing underscores. The function sets `val`
1344 to the corresponding integer enum constant or to a bitmask. The function
1345 returns `SOAP_OK` (zero) on success or an error if the string is not a valid
1346 enumeration name.
1347 
1348 🔝 [Back to table of contents](#)
1349 
1350 Numerical types {#toxsd5}
1351 ---------------
1352 
1353 Integer and floating point types are mapped to the equivalent built-in XSD
1354 types with the same sign and bit width.
1355 
1356 The `size_t` type is transient (not serializable) because its width is platform
1357 dependent. We recommend to use `uint64_t` instead.
1358 
1359 The XML value space of integer types are their decimal representations without
1360 loss of precision.
1361 
1362 The XML value space of floating point types are their decimal representations.
1363 The decimal representations are formatted with the printf format string `"%.9G"`
1364 for floats and the printf format string `"%.17lG"` for double. To change the
1365 format strings, we can assign new strings to the following `soap` context
1366 members:
1367 
1368 ~~~{.cpp}
1369  soap.float_format = "%g";
1370  soap.double_format = "%lg";
1371  soap.long_double_format = "%Lg";
1372 ~~~
1373 
1374 Decimal representations may result in a loss of precision of the least
1375 significant decimal. Therefore, the format strings that are used by default
1376 are sufficiently precise to avoid loss, but this may result in long decimal
1377 fractions in the XML value space.
1378 
1379 The `long double` extended floating point type requires a custom serializer:
1380 
1381 ~~~{.cpp}
1382  #import "custom/long_double.h"
1383  ... // use long double
1384 ~~~
1385 
1386 You can now use `long double`, which has a serializer that serializes this type
1387 as <i>`xsd:decimal`</i>. Compile and link your code with the file
1388 <i>`gsoap/custom/long_double.c`</i>.
1389 
1390 The value space of floating point values includes the special values
1391 <i>`INF`</i>, <i>`-INF`</i>, and <i>`NaN`</i>. You can check a value for plus
1392 or minus infinity and not-a-number as follows:
1393 
1394 ~~~{.cpp}
1395  soap_isinf(x) && x > 0 // is x INF?
1396  soap_isinf(x) && x < 0 // is x -INF?
1397  soap_isnan(x) // is x NaN?
1398 ~~~
1399 
1400 To assign these values, use:
1401 
1402 ~~~{.cpp}
1403  // x is float // x is double, long double, or __float128
1404  x = FLT_PINFY; x = DBL_PINFTY;
1405  x = FLT_NINFY; x = DBL_NINFTY;
1406  x = FLT_NAN; x = DBL_NAN;
1407 ~~~
1408 
1409 If your system supports `__float128` then you can also use this 128 bit
1410 floating point type with a custom serializer:
1411 
1412 ~~~{.cpp}
1413  #import "custom/float128.h"
1414  ... // use xsd__decimal
1415 ~~~
1416 
1417 Then use the `xsd__decimal` alias of `__float128`, which has a serializer. Do
1418 not use `__float128` directly, which is transient (not serializable).
1419 
1420 To check for <i>`INF`</i>, <i>`-INF`</i>, and <i>`NaN`</i> of a `__float128`
1421 value use:
1422 
1423 ~~~{.cpp}
1424  isinfq(x) && x > 0 // is x INF?
1425  isinfq(x) && x < 0 // is x -INF?
1426  isnanq(x) // is x NaN?
1427 ~~~
1428 
1429 The range of a `typedef`-defined numerical type can be restricted using the range
1430 `:` operator with inclusive lower and upper bounds. For example:
1431 
1432 ~~~{.cpp}
1433  typedef int ns__narrow -10 : 10;
1434 ~~~
1435 
1436 This maps to a simpleType restriction of <i>`xsd:int`</i> in the soapcpp2-generated
1437 schema:
1438 
1439 <div class="alt">
1440 ~~~{.xml}
1441  <simpleType name="narrow">
1442  <restriction base="xsd:int">
1443  <minInclusive value="-10"/>
1444  <maxInclusive value="10"/>
1445  </restriction>
1446  </simpleType>
1447 ~~~
1448 </div>
1449 
1450 The lower and upper bound of a range are optional. When omitted, values are
1451 not bound from below or from above, respectively.
1452 
1453 The range of a floating point `typedef`-defined type can be restricted within
1454 floating point constant bounds.
1455 
1456 Also with a floating point `typedef` a `printf`-format pattern can be given of the
1457 form `"%[width][.precision]f"` to format decimal values using the given width
1458 and precision fields:
1459 
1460 ~~~{.cpp}
1461  typedef float ns__PH "%5.2f" 0.0 : 14.0;
1462 ~~~
1463 
1464 This maps to a simpleType restriction of <i>`xsd:float`</i> in the soapcpp2-generated
1465 schema:
1466 
1467 <div class="alt">
1468 ~~~{.xml}
1469  <simpleType name="PH">
1470  <restriction base="xsd:float">
1471  <totalDigits value="5"/>
1472  <fractionDigits value="2"/>
1473  <minInclusive value="0"/>
1474  <maxInclusive value="14"/>
1475  </restriction>
1476  </simpleType>
1477 ~~~
1478 </div>
1479 
1480 For exclusive bounds, we use the `<` operator instead of the `:` range
1481 operator:
1482 
1483 ~~~{.cpp}
1484  typedef float ns__epsilon 0.0 < 1.0;
1485 ~~~
1486 
1487 Values `eps` of `ns__epsilon` are restricted between `0.0 < eps < 1.0`.
1488 
1489 This maps to a simpleType restriction of <i>`xsd:float`</i> in the soapcpp2-generated
1490 schema:
1491 
1492 <div class="alt">
1493 ~~~{.xml}
1494  <simpleType name="epsilon">
1495  <restriction base="xsd:float">
1496  <minExclusive value="0"/>
1497  <maxExclusive value="1"/>
1498  </restriction>
1499  </simpleType>
1500 ~~~
1501 </div>
1502 
1503 To make just one of the bounds exclusive, while keeping the other bound
1504 inclusive, we add a `<` on the left or on the right side of the range ':'
1505 operator. For example:
1506 
1507 ~~~{.cpp}
1508  typedef float ns__pos 0.0 < : ; // 0.0 < pos
1509  typedef float ns__neg : < 0.0 ; // neg < 0.0
1510 ~~~
1511 
1512 It is valid to make both left and right side exclusive with `< : <` which is in
1513 fact identical to the exlusive range `<` operator:
1514 
1515 ~~~{.cpp}
1516  typedef float ns__epsilon 0.0 < : < 1.0; // 0.0 < eps < 1.0
1517 ~~~
1518 
1519 It helps to think of the `:` as a placeholder of the value between the two
1520 bounds, which is easier to memorize than the shorthand forms of bounds from
1521 which the `:` is removed:
1522 
1523 | bounds | validation check | shorthand |
1524 | ------------ | ---------------- | ----------- |
1525 | `1 : ` | 1 <= x | `1 ` |
1526 | `1 : 10 ` | 1 <= x <= 10 | |
1527 | ` : 10 ` | x <= 10 | |
1528 | `1 < : < 10` | 1 < x < 10 | `1 < 10 ` |
1529 | `1 : < 10` | 1 <= x < 10 | |
1530 | ` : < 10` | x < 10 | ` < 10 ` |
1531 | `1 < : ` | 1 < x | `1 < ` |
1532 | `1 < : 10 ` | 1 < x <= 10 | |
1533 
1534 Besides `float`, also `double` and `long double` values can be restricted. For
1535 example, consider a nonzero probability extended floating point precision type:
1536 
1537 ~~~{.cpp}
1538  #import "custom/long_double.h"
1539  typedef long double ns__probability "%16Lg" 0.0 < : 1.0;
1540 ~~~
1541 
1542 Value range restrictions are validated by the parser for all inbound XML data.
1543 A type fault `SOAP_TYPE` will be thrown by the deserializer if the value is out
1544 of range.
1545 
1546 Finally, if your system supports `__int128_t` then you can also use this 128
1547 bit integer type with a custom serializer:
1548 
1549 ~~~{.cpp}
1550  #import "custom/int128.h"
1551  ... // use xsd__integer
1552 ~~~
1553 
1554 Use the `xsd__integer` alias of `__int128_t`, which has a serializer. Do not
1555 use `__int128_t` directly, which is transient (not serializable).
1556 
1557 To convert numeric values to a string, we use the auto-generated function for
1558 numeric type `T`:
1559 
1560 ~~~{.cpp}
1561  const char *soap_T2s(struct soap*, T val)
1562 ~~~
1563 
1564 For numeric types `T`, the string returned is stored in an internal buffer of
1565 the current `soap` context, so you should copy it to keep it from being
1566 overwritten. For example, use `char *soap_strdup(struct soap*, const char*)`.
1567 
1568 To convert a string to a numeric value, we use the auto-generated function
1569 
1570 ~~~{.cpp}
1571  int soap_s2T(struct soap*, const char *str, T *val)
1572 ~~~
1573 
1574 where `T` is for example `int`, `LONG64`, `float`, `decimal` (the custom
1575 serializer name of `long double`) or `xsd__integer` (the custom serializer name
1576 of `__int128_t`). The function `soap_s2T` returns `SOAP_OK` on success or an
1577 error when the value is not numeric. For floating point types, `"INF"`, `"-INF"`
1578 and `"NaN"` are valid strings to convert to numbers.
1579 
1580 🔝 [Back to table of contents](#)
1581 
1582 String types {#toxsd6}
1583 ------------
1584 
1585 String types are mapped to the built-in <i>`xsd:string`</i> and <i>`xsd:QName`</i> XSD types.
1586 
1587 The wide strings `wchar_t*` and `std::wstring` may contain Unicode that is
1588 preserved in the XML value space.
1589 
1590 Strings `char*` and `std::string` can only contain extended Latin, but we can
1591 store UTF-8 content that is preserved in the XML value space when the `soap`
1592 context is initialized with the flag `SOAP_C_UTFSTRING`.
1593 
1594 @warning Beware that many XML 1.0 parsers reject all control characters (those
1595 between `#x1` and `#x1F`) except for `#x9`, `#xA`, and `#xD`. With the
1596 newer XML 1.1 version parsers (including gSOAP) you should be fine.
1597 
1598 The length of a string of a `typedef`-defined string type can be restricted:
1599 
1600 ~~~{.cpp}
1601  typedef std::string ns__password 6 : 16;
1602 ~~~
1603 
1604 which maps to a simpleType restriction of <i>`xsd:string`</i> in the soapcpp2-generated
1605 schema:
1606 
1607 <div class="alt">
1608 ~~~{.xml}
1609  <simpleType name="password">
1610  <restriction base="xsd:string">
1611  <minLength value="6"/>
1612  <maxLength value="16"/>
1613  </restriction>
1614  </simpleType>
1615 ~~~
1616 </div>
1617 
1618 String length restrictions are validated by the parser for inbound XML data.
1619 A value length fault `SOAP_LENGTH` will be thrown by the deserializer if the
1620 string is too long or too short.
1621 
1622 In addition, an XSD regex pattern restriction can be associated with a string
1623 typedef:
1624 
1625 ~~~{.cpp}
1626  typedef std::string ns__password "([a-zA-Z]|[0-9]|-)+" 6 : 16;
1627 ~~~
1628 
1629 which maps to a simpleType restriction of <i>`xsd:string`</i> in the soapcpp2-generated
1630 schema:
1631 
1632 <div class="alt">
1633 ~~~{.xml}
1634  <simpleType name="password">
1635  <restriction base="xsd:string">
1636  <pattern value="([a-zA-Z0-9]|-)+"/>
1637  <minLength value="6"/>
1638  <maxLength value="16"/>
1639  </restriction>
1640  </simpleType>
1641 ~~~
1642 </div>
1643 
1644 Pattern restrictions are validated by the parser for inbound XML data only if
1645 the `soap::fsvalidate` and `soap::fwvalidate` callbacks are defined.
1646 
1647 Exclusive length bounds can be used with strings:
1648 
1649 ~~~{.cpp}
1650  typedef std::string ns__string255 : < 256; // same as 0 : 255
1651 ~~~
1652 
1653 Fixed-size strings (`char[N]`) are rare occurrences in the wild, but apparently
1654 still used in some projects to store strings. To facilitate fixed-size string
1655 serialization, use <b>`soapcpp2 -b`</b> option <b>`-b`</b>. For example:
1656 
1657 ~~~{.cpp}
1658  typedef char ns__buffer[10]; // requires soapcpp2 option -b
1659 ~~~
1660 
1661 which maps to a simpleType restriction of <i>`xsd:string`</i> in the soapcpp2-generated
1662 schema:
1663 
1664 <div class="alt">
1665 ~~~{.xml}
1666  <simpleType name="buffer">
1667  <restriction base="xsd:string">
1668  <maxLength value="9"/>
1669  </restriction>
1670  </simpleType>
1671 ~~~
1672 </div>
1673 
1674 Fixed-size strings must contain NUL-terminated text and should not contain raw
1675 binary data. Also, the length limitation is more restrictive for UTF-8 content
1676 (enabled with the `SOAP_C_UTFSTRING`) that requires multibyte character
1677 encodings. As a consequence, UTF-8 content may be truncated to fit.
1678 
1679 Raw binary data can be stored in a `xsd__base64Binary` or `xsd__hexBinary`
1680 structure, or transmitted as a MIME attachment.
1681 
1682 The built-in `_QName` type is a regular C string type (`char*`) that maps to
1683 <i>`xsd:QName`</i> but has the added advantage that it holds normalized qualified names.
1684 There are actually two forms of normalized QName content, to ensure any QName
1685 is represented accurately:
1686 
1687 ~~~{.cpp}
1688  "prefix:name"
1689  "\"URI\":name"
1690 ~~~
1691 
1692 The first form of string is used when the prefix (and the binding URI) is
1693 defined in the namespace table and is bound to a URI (see the .nsmap file).
1694 The second form is used when the URI is not defined in the namespace table and
1695 therefore no prefix is available to bind and normalize the URI to.
1696 
1697 A `_QName` string may contain a sequence of space-separated QName values, not
1698 just one, and all QName values are normalized to the format shown above.
1699 
1700 To define a `std::string` base type for <i>`xsd:QName`</i>, we use a `typedef`:
1701 
1702 ~~~{.cpp}
1703  typedef std::string xsd__QName;
1704 ~~~
1705 
1706 The `xsd__QName` string content is normalized, just as with the `_QName`
1707 normalization.
1708 
1709 To serialize strings that contain literal XML content to be reproduced in the
1710 XML value space, use the built-in `_XML` string type, which is a regular C
1711 string type (`char*`) that maps to plain XML CDATA.
1712 
1713 To define a `std::string` base type for literal XML content, use a `typedef`:
1714 
1715 ~~~{.cpp}
1716  typedef std::string XML;
1717 ~~~
1718 
1719 Strings can hold any of the values of the XSD built-in primitive types. We can
1720 use a string `typedef` to declare the use of the string type as a XSD built-in
1721 type:
1722 
1723 ~~~{.cpp}
1724  typedef std::string xsd__token;
1725 ~~~
1726 
1727 You must ensure that the string values we populate in this type conform to the
1728 XML standard, which in case of <i>`xsd:token`</i> is the lexical and value spaces of
1729 <i>`xsd:token`</i> are the sets of all strings after whitespace replacement of any
1730 occurrence of `#x9`, `#xA` , and `#xD` by `#x20` and collapsing.
1731 
1732 As of version 2.8.49, the gSOAP parser will automatically collapse or replace
1733 the white space content when receiving data for XSD types that require white
1734 space collapsed or replaced. This normalization is applied to strings
1735 directly. The decision to collapse or replace is based on the `typedef` name
1736 corresponding to the built-in string-based XSD type.
1737 
1738 To copy `char*` or `wchar_t*` strings with a context that manages the allocated
1739 memory, use functions
1740 
1741 ~~~{.cpp}
1742  char *soap_strdup(struct soap*, const char*)
1743  wchar_t *soap_wstrdup(struct soap*, const wchar_t*)
1744 ~~~
1745 
1746 To convert a wide string to a UTF-8 encoded string, use function
1747 
1748 ~~~{.cpp}
1749  const char* SOAP_FMAC2 soap_wchar2s(struct soap*, const wchar_t *s)
1750 ~~~
1751 
1752 The function allocates and returns a string, with its memory being managed by
1753 the context.
1754 
1755 To convert a UTF-8 encoded string to a wide string, use function
1756 
1757 ~~~{.cpp}
1758  int soap_s2wchar(struct soap*, const char *from, wchar_t **to, long minlen, long maxlen)
1759 ~~~
1760 
1761 where `to` is set to point to an allocated `wchar_t*` string. Pass `-1` for
1762 `minlen` and `maxlen` to ignore length constraints on the target string. The
1763 function returns `SOAP_OK` or an error when the length constraints are not met.
1764 
1765 🔝 [Back to table of contents](#)
1766 
1767 Date and time types {#toxsd7}
1768 -------------------
1769 
1770 The C/C++ `time_t` type is mapped to the built-in <i>`xsd:dateTime`</i> XSD type that
1771 represents a date and time within a time zone (typically UTC).
1772 
1773 The XML value space contains ISO 8601 Gregorian time instances of the form
1774 <i>`[-]CCYY-MM-DDThh:mm:ss.sss[Z|(+|-)hh:mm]`</i>, where <i>`Z`</i> is the UTC time zone
1775 or a time zone offset <i>`(+|-)hh:mm]`</i> from UTC is used.
1776 
1777 A `time_t` value is considered and represented in UTC by the serializer.
1778 
1779 Because the `time_t` value range is restricted to dates after 01/01/1970 and
1780 before 2038 assuming `time_t` is a `long` 32 bit, care must be taken to ensure
1781 the range of <i>`xsd:dateTime`</i> values in XML exchanges do not exceed the `time_t`
1782 range.
1783 
1784 This restriction does not hold for `struct tm` (<i>`time.h`</i> library), which we can use
1785 to store and exchange a date and time in UTC without date range restrictions.
1786 The serializer uses the `struct tm` members directly for the XML value space of
1787 <i>`xsd:dateTime`</i>:
1788 
1789 ~~~{.cpp}
1790  struct tm
1791  {
1792  int tm_sec; // seconds (0 - 60)
1793  int tm_min; // minutes (0 - 59)
1794  int tm_hour; // hours (0 - 23)
1795  int tm_mday; // day of month (1 - 31)
1796  int tm_mon; // month of year (0 - 11)
1797  int tm_year; // year - 1900
1798  int tm_wday; // day of week (Sunday = 0) (NOT USED)
1799  int tm_yday; // day of year (0 - 365) (NOT USED)
1800  int tm_isdst; // is summer time in effect?
1801  char* tm_zone; // abbreviation of timezone (NOT USED)
1802  };
1803 ~~~
1804 
1805 You will lose the day of the week information. It is always Sunday
1806 (`tm_wday=0`) and the day of the year is not set either. The time zone is UTC.
1807 
1808 This `struct tm` type is mapped to the built-in <i>`xsd:dateTime`</i> XSD type and
1809 serialized with the custom serializer <i>`gsoap/custom/struct_tm.h`</i> that declares a
1810 `xsd__dateTime` type:
1811 
1812 ~~~{.cpp}
1813  #import "custom/struct_tm.h" // import typedef struct tm xsd__dateTime;
1814  ... // use xsd__dateTime
1815 ~~~
1816 
1817 Compile and link your code with <i>`gsoap/custom/struct_tm.c`</i>.
1818 
1819 The `struct timeval` (<i>`sys/time.h`</i> library) type is mapped to the
1820 built-in <i>`xsd:dateTime`</i> XSD type and serialized with the custom serializer
1821 <i>`gsoap/custom/struct_timeval.h`</i> that declares a `xsd__dateTime` type:
1822 
1823 ~~~{.cpp}
1824  #import "custom/struct_timeval.h" // import typedef struct timeval xsd__dateTime;
1825  ... // use xsd__dateTime
1826 ~~~
1827 
1828 Compile and link your code with <i>`gsoap/custom/struct_timeval.c`</i>.
1829 
1830 The same value range restrictions apply to `struct timeval` as they apply to
1831 `time_t`. The added benefit of `struct timeval` is the addition of a
1832 microsecond-precise clock:
1833 
1834 ~~~{.cpp}
1835  struct timeval
1836  {
1837  time_t tv_sec; // seconds since Jan. 1, 1970
1838  suseconds_t tv_usec; // and microseconds
1839  };
1840 ~~~
1841 
1842 A C++11 `std::chrono::system_clock::time_point` type is mapped to the built-in
1843 <i>`xsd:dateTime`</i> XSD type and serialized with the custom serializer
1844 <i>`gsoap/custom/chrono_time_point.h`</i> that declares a `xsd__dateTime` type:
1845 
1846 ~~~{.cpp}
1847  #import "custom/chrono_time_point.h" // import typedef std::chrono::system_clock::time_point xsd__dateTime;
1848  ... // use xsd__dateTime
1849 ~~~
1850 
1851 Compile and link your code with <i>`gsoap/custom/chrono_time_point.cpp`</i>.
1852 
1853 The `struct tm` type is mapped to the built-in <i>`xsd:date`</i> XSD type and serialized
1854 with the custom serializer <i>`gsoap/custom/struct_tm_date.h`</i> that declares a
1855 `xsd__date` type:
1856 
1857 ~~~{.cpp}
1858  #import "custom/struct_tm_date.h" // import typedef struct tm xsd__date;
1859  ... // use xsd__date
1860 ~~~
1861 
1862 Compile and link your code with <i>`gsoap/custom/struct_tm_date.c`</i>.
1863 
1864 The XML value space of <i>`xsd:date`</i> are Gregorian calendar dates of the form
1865 <i>`[-]CCYY-MM-DD[Z|(+|-)hh:mm]`</i> with a time zone.
1866 
1867 The serializer ignores the time part and the deserializer only populates the
1868 date part of the struct, setting the time to 00:00:00. There is no unreasonable
1869 limit on the date range because the year field is stored as an integer (`int`).
1870 
1871 An `unsigned long long` (`ULONG64` or `uint64_t`) type that contains a 24 hour
1872 time in microseconds UTC is mapped to the built-in <i>`xsd:time`</i> XSD type and
1873 serialized with the custom serializer <i>`gsoap/custom/long_time.h`</i> that declares a
1874 `xsd__time` type:
1875 
1876 ~~~{.cpp}
1877  #import "custom/long_time.h" // import typedef unsigned long long xsd__time;
1878  ... // use xsd__time
1879 ~~~
1880 
1881 Compile and link your code with <i>`gsoap/custom/long_time.c`</i>.
1882 
1883 This type represents `00:00:00.000000` to `23:59:59.999999`, from 0 to an
1884 upper bound of 86,399,999,999. A microsecond resolution means that a 1 second
1885 increment requires an increment of 1,000,000 in the integer value.
1886 
1887 The XML value space of <i>`xsd:time`</i> are points in time recurring each day of the
1888 form <i>`hh:mm:ss.sss[Z|(+|-)hh:mm]`</i>, where <i>`Z`</i> is the UTC time zone or a time
1889 zone offset from UTC is used. The `xsd__time` value is always considered and
1890 represented in UTC by the serializer.
1891 
1892 To convert date and/or time values to a string, we use the auto-generated
1893 function for type `T`:
1894 
1895 ~~~{.cpp}
1896  const char *soap_T2s(struct soap*, T val)
1897 ~~~
1898 
1899 For date and time types `T`, the string returned is stored in an internal
1900 buffer of the current `soap` context, so you should copy it to keep it from being
1901 overwritten. For example, use `char *soap_strdup(struct soap*, const char*)`.
1902 
1903 To convert a string to a date/time value, we use the auto-generated function
1904 
1905 ~~~{.cpp}
1906  int soap_s2T(struct soap*, const char *str, T *val)
1907 ~~~
1908 
1909 where `T` is for example `dateTime` (for `time_t`), `xsd__dateTime` (for
1910 `struct tm`, `struct timeval`, or `std::chrono::system_clock::time_point`).
1911 The function `soap_s2T` returns `SOAP_OK` on success or an error when the value
1912 is not a date/time.
1913 
1914 🔝 [Back to table of contents](#)
1915 
1916 Time duration types {#toxsd8}
1917 -------------------
1918 
1919 The XML value space of <i>`xsd:duration`</i> are values of the form <i>`PnYnMnDTnHnMnS`</i>
1920 where the capital letters are delimiters. Delimiters may be omitted when the
1921 corresponding member is not used.
1922 
1923 A `long long` (`LONG64` or `int64_t`) type that contains a duration (time
1924 lapse) in milliseconds is mapped to the built-in <i>`xsd:duration`</i> XSD type and
1925 serialized with the custom serializer <i>`gsoap/custom/duration.h`</i> that declares a
1926 `xsd__duration` type:
1927 
1928 ~~~{.cpp}
1929  #import "custom/duration.h" // import typedef long long xsd__duration;
1930  ... // use xsd__duration
1931 ~~~
1932 
1933 Compile and link your code with <i>`gsoap/custom/duration.c`</i>.
1934 
1935 The duration type `xsd__duration` can represent 106,751,991,167 days forward
1936 and backward with millisecond precision.
1937 
1938 Durations that exceed a month are always output in days, rather than months to
1939 avoid days-per-month conversion inacurracies.
1940 
1941 Durations that are received in years and months instead of total number of days
1942 from a reference point are not well defined, since there is no accepted
1943 reference time point (it may or may not be the current time). The decoder
1944 simple assumes that there are 30 days per month. For example, conversion of
1945 "P4M" gives 120 days. Therefore, the durations "P4M" and "P120D" are assumed
1946 to be identical, which is not necessarily true depending on the reference point
1947 in time.
1948 
1949 Rescaling of the duration value by may be needed when adding the duration value
1950 to a `time_t` value, because `time_t` may or may not have a seconds resolution,
1951 depending on the platform and possible changes to `time_t`.
1952 
1953 Rescaling is done automatically when you add a C++11 `std::chrono::nanoseconds`
1954 value to a `std::chrono::system_clock::time_point` value. To use
1955 `std::chrono::nanoseconds` as <i>`xsd:duration`</i>:
1956 
1957 ~~~{.cpp}
1958  #import "custom/chrono_duration.h" // import typedef std::chrono::duration xsd__duration;
1959  ... // use xsd__duration
1960 ~~~
1961 
1962 Compile and link your code with <i>`gsoap/custom/chrono_duration.cpp`</i>.
1963 
1964 This type can represent 384,307,168 days (2^63 nanoseconds) forwards and
1965 backwards in time in increments of 1 ns (1/1000000000 second).
1966 
1967 The same observations with respect to receiving durations in years and months
1968 apply to this serializer's decoder.
1969 
1970 To convert duration values to a string, we use the auto-generated function
1971 
1972 ~~~{.cpp}
1973  const char *soap_xsd__duration2s(struct soap*, xsd__duration val)
1974 ~~~
1975 
1976 The string returned is stored in an internal buffer, so you should copy it to
1977 keep it from being overwritten, Use `soap_strdup(struct soap*, const char*)`
1978 for example to copy this string.
1979 
1980 To convert a string to a duration value, we use the auto-generated function
1981 
1982 ~~~{.cpp}
1983  int soap_s2xsd__dateTime(struct soap*, const char *str, xsd__dateTime *val)
1984 ~~~
1985 
1986 The function returns `SOAP_OK` on success or an error when the value is not a
1987 duration.
1988 
1989 🔝 [Back to table of contents](#)
1990 
1991 Classes and structs {#toxsd9}
1992 -------------------
1993 
1994 Classes and structs are mapped to XSD complexTypes. The XML value space
1995 consists of XML elements with attributes and subelements, possibly constrained
1996 by XML schema validation rules that enforce element and attribute occurrence
1997 contraints, numerical value range constraints, and string length and pattern
1998 constraints.
1999 
2000 Classes that are declared with the gSOAP tools are limited to single
2001 inheritence only. The soapcpp2 tool does not allow structs to be inherited.
2002 
2003 The class and struct name is bound to an XML namespace by means of the prefix
2004 naming convention or by using [colon notation](#toxsd1):
2005 
2006 ~~~{.cpp}
2007  //gsoap ns schema namespace: urn:types
2008  class ns__record
2009  {
2010  public:
2011  std::string name;
2012  uint64_t SSN;
2013  ns__record *spouse;
2014  ns__record();
2015  ~ns__record();
2016  protected:
2017  struct soap *soap;
2018  };
2019 ~~~
2020 
2021 In the example above, we also added a context pointer to the `soap` context that
2022 manages this instance. It is set when the instance is created in the engine's
2023 context, for example when deserialized and populated by the engine.
2024 
2025 The class maps to a complexType in the soapcpp2-generated XML schema:
2026 
2027 <div class="alt">
2028 ~~~{.xml}
2029  <complexType name="record">
2030  <sequence>
2031  <element name="name" type="xsd:string" minOccurs="1" maxOccurs="1"/>
2032  <element name="SSN" type="xsd:unsignedLong" minOccurs="1" maxOccurs="1"/>
2033  <element name="spouse" type="ns:record" minOccurs="0" maxOccurs="1" nillable="true"/>
2034  </sequence>
2035  </complexType>
2036 ~~~
2037 </div>
2038 
2039 The following sections apply to both structs and classes. Structs require the
2040 use of the `struct` keyword with the struct name, otherwise soapcpp2 will throw
2041 a syntax error. As is often done in C, use a `typedef` to declare a `struct`
2042 that can be used without the `struct` keyword.
2043 
2044 🔝 [Back to table of contents](#)
2045 
2046 ### Serializable versus transient types and data members {#toxsd9-1}
2047 
2048 Public data members of a class or struct are serializable when their types are
2049 serializable. Private and protected members are transient and not
2050 serializable.
2051 
2052 Also `const` and `static` members are not serializable, with the exception of
2053 `const char*` and `const wchar_t*`. Types and specific class/struct members
2054 can be made transient with the `extern` qualifier for types and by marking
2055 members with `[` and `]`:
2056 
2057 ~~~{.cpp}
2058  extern class std::ostream; // declare std::ostream transient
2059  class ns__record
2060  {
2061  public:
2062  [ int num; ] // not serialized: member is marked transient with [ ]
2063  std::ostream out; // not serialized: std:ostream is transient
2064  static const int MAX = 1024; // not serialized: static const member
2065  private:
2066  std::string id; // not serialized: private member
2067  };
2068 ~~~
2069 
2070 By declaring `std::ostream` transient with `extern` you can use this type
2071 wherever you need it without soapcpp2 complaining that this class and any other
2072 class or type declared as `extern` is not defined. Do not use `extern` with
2073 `typedef`, because this declares a custom serializer, see
2074 [adding custom serializers](#custom).
2075 
2076 Marking members transient with `[` and `]` makes them transient (and visually
2077 makes them stand out). This has otherwise no effect on the generated code for
2078 the class or struct to be used in your application code.
2079 
2080 🔝 [Back to table of contents](#)
2081 
2082 ### Derived types in C++ {#toxsd9-1-1}
2083 
2084 Extensible and restricted types in XML schemas are derived types from single
2085 simple and complex base types. XML schema derived types are naturally
2086 represented by C++ derived classes using single inheritance. Besides the
2087 concept of extensions versus restrictions, there are two kinds of derived
2088 types: complexTypes with simpleContent, meaning types with XML CDATA values,
2089 and complexTypes with complexContent, meaning types with sub-elements. Both
2090 are permitted to have one or more XML attributes.
2091 
2092 A complexType with simpleContent is defined as a wrapper to contain XML CDATA
2093 values and any number of attributes, see
2094 [wrapper class/struct with simpleContent](#toxsd10-4).
2095 Wrapper class/struct types can form a hierarchy of derived types in C++ using
2096 inheritance. For example:
2097 
2098 ~~~{.cpp}
2099  class xsd__anyType
2100  {
2101  public:
2102  std::string __item; // string to hold any simpleContent
2103  };
2104  class ns__data : public xsd__anyType
2105  {
2106  public:
2107  @ std::string value 1; // extends xsd:anyType with a required attribute
2108  };
2109 ~~~
2110 
2111 The `ns__data` class maps to a complexType in the soapcpp2-generated XML schema:
2112 
2113 <div class="alt">
2114 ~~~{.xml}
2115  <complexType name="string">
2116  <simpleContent>
2117  <extension base="xsd:string">
2118  <attribute name="value" type="xsd:string" use="required"/>
2119  </extension>
2120  </simpleContent>
2121  </complexType>
2122 ~~~
2123 </div>
2124 
2125 The XML value space consists of an element with the string contents an optional
2126 attribute:
2127 
2128 <div class="alt">
2129 ~~~{.xml}
2130  <ns:data value="abc">xyz</ns:data>
2131 ~~~
2132 </div>
2133 
2134 By contrast, a complexType with complexContent typically extends a given base
2135 complexType. For example:
2136 
2137 ~~~{.cpp}
2138  class ns__base
2139  {
2140  public:
2141  std::string name 1;
2142  int number 1;
2143  };
2144  class ns__derived : public ns__base
2145  {
2146  public:
2147  @ std::string value 1; // extends ns:base with an attribute
2148  std::string text 1; // extends ns:base with an element
2149  };
2150 ~~~
2151 
2152 The `ns__base` and `ns__derived` classes maps to complexTypes in the soapcpp2-generated XML schema:
2153 
2154 <div class="alt">
2155 ~~~{.xml}
2156  <complexType name="base">
2157  <sequence>
2158  <element name="name" type="xsd:string" minOccurs="1" maxOccurs="1"/>
2159  <element name="number" type="xsd:int" minOccurs="1" maxOccurs="1"/>
2160  </sequence>
2161  </complexType>
2162  <complexType name="derived">
2163  <complexContent>
2164  <extension base="ns:base">
2165  <sequence>
2166  <element name="text" type="xsd:string" minOccurs="1" maxOccurs="1"/>
2167  </sequence>
2168  </extension>
2169  </complexContent>
2170  <attribute name="value" type="xsd:string" use="required"/>
2171  </complexType>
2172 ~~~
2173 </div>
2174 
2175 The XML value space of `ns__derived` consists of three requires child elements
2176 and an optional attribute:
2177 
2178 <div class="alt">
2179 ~~~{.xml}
2180  <ns:derived value="abc">
2181  <name>def</name>
2182  <number>123</number>
2183  <text>xyz</text>
2184  </ns:derived>
2185 ~~~
2186 </div>
2187 
2188 Derived types can be used for two main purposes in XML schema by extending or
2189 restricting base types. One purpose is to reuse a base type when defining a
2190 derived type, such that common parts do not need to be replicated. The second
2191 purpose is to be able to use a derived type in place of a base type in XML, which
2192 is indicated by an <i>`xsi:type`</i> attribute with the qualified name of the
2193 derived type. Consider for example the following class that uses the
2194 previously declared base types `xsd__anyType` and `ns__base`:
2195 
2196 ~~~{.cpp}
2197  class ns__record
2198  {
2199  public:
2200  xsd__anyType *base1 1; // required element
2201  ns__base *base2 1; // required element
2202  };
2203 ~~~
2204 
2205 We can assign base type values to the `ns_record` members:
2206 
2207 ~~~{.cpp}
2208  ns__record record;
2209  record.base1 = soap_new_xsd__anyType(soap);
2210  record.base2 = soap_new_ns__base(soap);
2211  soap_write_ns__record(soap, &record);
2212 ~~~
2213 
2214 This produces the following XML fragment populated with default values (empty
2215 text for strings and zeros for numbers), where element <i>`base1`</i> has a
2216 simpleContent value and element <i>`base2`</i> has two child elements:
2217 
2218 <div class="alt">
2219 ~~~{.xml}
2220  <ns:record>
2221  <base1></base1>
2222  <base2>
2223  <name></name>
2224  <number>0</number>
2225  </base2>
2226  </ns:record>
2227 ~~~
2228 </div>
2229 
2230 We can also assign derived type values to the `ns_record` members:
2231 
2232 ~~~{.cpp}
2233  ns__record record;
2234  record.base1 = soap_new_ns__data(soap);
2235  record.base2 = soap_new_ns__derived(soap);
2236  soap_write_ns__record(soap, &record);
2237 ~~~
2238 
2239 This produces the following XML fragment populated with default values (empty
2240 text for strings and zeros for numbers), where element <i>`base1`</i> has
2241 schema type <i>`ns:data`</i> with simpleContent and an attribute, and
2242 <i>`base2`</i> has schema type <i>`ns:derived`</i> with three child elements
2243 and an attribute:
2244 
2245 <div class="alt">
2246 ~~~{.xml}
2247  <ns:record>
2248  <base1 xsi:type="ns:data" value=""></base1>
2249  <base2 xsi:type="ns:derived" value="">
2250  <name></name>
2251  <number>0</number>
2252  <text></text>
2253  </base2>
2254  </ns:record>
2255 ~~~
2256 </div>
2257 
2258 Deserialization automatically allocates and assigns a `ns__base` class instance to a
2259 `ns__base` pointer when deserializing the <i>`ns:base`</i> schema type and allocates and
2260 assigns a `ns__derived` class instance to a `ns__base` pointer when deserializing the
2261 <i>`ns:derived`</i> type when an element with <i>`xsi:type="ns:derived"`</i> is
2262 parsed. All classes are extended by soapcpp2 by a `soap_type()` method that
2263 returns the unique `SOAP_TYPE_T` value of the class `T`. This makes it easy to
2264 check whether the deserialized data contains a derived type to implement
2265 type-safe code, for example:
2266 
2267 ~~~{.cpp}
2268  ns__record record;
2269  soap_read_ns__record(soap, &record);
2270  if (record.base1->soap_type() == SOAP_TYPE_ns__data)
2271  std::cout << "Derived ns:data "
2272  << dynamic_cast<ns__data*>(record.base1)->value
2273  << std::endl;
2274  else
2275  std::cout << "Base xsd:anyType" << std::endl;
2276  if (record.base2->soap_type() == SOAP_TYPE_ns__derived)
2277  std::cout << "Derived ns:derived "
2278  << dynamic_cast<ns__derived*>(record.base2)->value
2279  << std::endl;
2280  else
2281  std::cout << "Base ns:base" << std::endl;
2282 ~~~
2283 
2284 This example should use the `SOAP_XML_STRICT` mode flag to initialize the
2285 `soap` context to ensure that all required values are present in the
2286 deserialized structures.
2287 
2288 🔝 [Back to table of contents](#)
2289 
2290 ### Derived types in C {#toxsd9-1-2}
2291 
2292 While single inheritance works well in C++ to represent derived types as we
2293 discussed in the previous section, this will obviously not work in C. Two
2294 methods to serialize derived types in C are presented here. The first method
2295 uses `void*` to serialize anything. The second method is more accurate and is
2296 relatively new in gSOAP.
2297 
2298 To serialize any type is possible with [tagged void pointer members](#toxsd9-12) to
2299 serialize data pointed to by a `void*` member, which can be any serializable
2300 type, such as derived types. For `void*` deserialization to work the XML
2301 parsed must contain an <i>`xsi:type`</i> attribute with a schema type. Only
2302 then can the deserializer instantiate the corresponding serializable C/C++
2303 type. Base types serialized do not require an <i>`xsi:type`</i> to indicate
2304 the base schema type, so this approach is not guaranteed to work and requires a
2305 workaround with an anonymous wrapper struct/class that contains both the base
2306 type and a `void*`. For example:
2307 
2308 ~~~{.cpp}
2309  struct ns__base // a base type
2310  {
2311  char *name 1;
2312  int number 1;
2313  };
2314  struct ns__derived // extends ns__base with two additional members
2315  {
2316  char *name 1;
2317  int number 1;
2318  char *text 1;
2319  @ char *value 1;
2320  };
2321  struct __ns__base // a wrapper, not visible in XML
2322  {
2323  int __type; // the SOAP_TYPE_T pointed to by __self
2324  void *__self; // points to any type
2325  struct ns__base *__self; // wraps ns__base for the current element tag
2326  }
2327  class ns__record
2328  {
2329  struct __ns__base base;
2330  };
2331 ~~~
2332 
2333 The `__ns__base` wrapper wraps the `ns__base` type to (de)serialize the
2334 <i>`base`</i> element that has no <i>`xsi:type`</i> attribute and uses `void*`
2335 to (de)serialize the <i>`base`</i> element that has <i>`xsi:type`</i>
2336 attribute. This works fine at the XML parsing level, but the generated
2337 XML schema components do not accurately represent the derived type, because it
2338 lacks the extension/restriction of the derived type (and the `__ns__base`
2339 wrapper is invisible).
2340 
2341 Using `void*` to represent derived types in a base type wrapper is not very
2342 accurate because we can serialize anything, not just derived types of a given
2343 base type. The wrapper may also hold two values: the base type value and a
2344 derived type value. Furthermore, using arrays or containers that hold base and
2345 derived types becomes quite tricky because an array item could hold both the
2346 base and derived type.
2347 
2348 As of gSOAP version 2.8.75, `wsdl2h -F` option `-F` generates base type structs
2349 extended with transient pointer members to its derived types. To serialize the
2350 base type itself, all of the pointer members are NULL. If one of the pointer
2351 members points to a derived type the derived type is serialized instead.
2352 Deserialization is automatic, in that the base type is deserialized if the
2353 element has no <i>`xsi:type`</i> attribute or the attribute is the base schema
2354 type, and a derived type is deserialized if the element has an
2355 <i>`xsi>type`</i> attribute with the derived schema type.
2356 
2357 This method is fully automated for the wsdl2h tool to generate an interface
2358 header file for soapcpp2 with the type derivations in C. To use this method to
2359 generate code from WSDLs and XSDs, use `wsdl2h -F` option `-F`. This also
2360 works in C++ if desired, but C++ inheritance works fine without this method.
2361 
2362 Using this method with soapcpp2 alone using a manually-specified interface
2363 header file produces the specified type inheritance in the soapcpp2-generated
2364 WSDL and XML schema files as complexType extensions.
2365 
2366 The soapcpp2 tool warns if a derived type has multiple base types. At most one
2367 base type for a derived type may be specified.
2368 
2369 This method with transient pointers to derived types makes it easy to use base
2370 and derived types in C:
2371 
2372 ~~~{.cpp}
2373  struct ns__base // a base type
2374  {
2375  char *name 1;
2376  int number 1;
2377  [ struct ns__derived *ns__derived; ] // points to derived type if non-NULL
2378  };
2379  struct ns__derived // extends ns__base with two additional members
2380  {
2381  char *name 1;
2382  int number 1;
2383  char *text 1;
2384  @ char *value 1;
2385  };
2386  struct ns__record
2387  {
2388  struct ns__base base; // contains base type or derived type value
2389  };
2390 ~~~
2391 
2392 The `ns__base` struct includes the special member `ns__derived` that points to
2393 a `ns__derived` value. This special member must be:
2394 
2395 - a transient member (i.e. non-serializable) by placing the declaration within
2396  `[` and `]`, and
2397 - the member name must match the type name (to be more precise, at least the
2398  initial part of the member name must match the type name as in the example
2399  `ns__derived_` works too).
2400 
2401 To serialize the `ns__base` value requires the `ns__derived` member to be NULL.
2402 To serialize the `ns__derived` value requires the `ns__derived` member to point
2403 to the `ns__derived` value to serialize and the `ns__base` members are
2404 irrelevant.
2405 
2406 We can assign the base type value to the `ns_record::base` member:
2407 
2408 ~~~{.cpp}
2409  struct ns__record record;
2410  soap_default_ns__record(soap, &record);
2411  soap_write_ns__record(soap, &record);
2412 ~~~
2413 
2414 This produces the following XML fragment populated with default values (empty
2415 text for strings and zeros for numbers), where element <i>`base`</i> has two
2416 child elements:
2417 
2418 <div class="alt">
2419 ~~~{.xml}
2420  <ns:record>
2421  <base>
2422  <name></name>
2423  <number>0</number>
2424  </base>
2425  </ns:record>
2426 ~~~
2427 </div>
2428 
2429 We can also assign the derived type value to the `ns_record::base` member:
2430 
2431 ~~~{.cpp}
2432  struct ns__record record;
2433  soap_default_ns__record(soap, &record);
2434  record.base.ns__derived = soap_new_ns__derived(soap, -1);
2435  soap_write_ns__record(soap, &record);
2436 ~~~
2437 
2438 This produces the following XML fragment populated with default values (empty
2439 text for strings and zeros for numbers), where element <i>`base`</i> has schema
2440 type <i>`ns:derived`</i> with three child elements and an attribute:
2441 
2442 <div class="alt">
2443 ~~~{.xml}
2444  <ns:record>
2445  <base xsi:type="ns:derived" value="">
2446  <name></name>
2447  <number>0</number>
2448  <text></text>
2449  </base>
2450  </ns:record>
2451 ~~~
2452 </div>
2453 
2454 Deserialization automatically assigns values to the base members for the
2455 `ns__base` type and populates the `ns__derived` member when a derived type with
2456 <i>`xsi:type="ns:derived"`</i> is parsed. This makes it easy to decompose the
2457 deserialized data:
2458 
2459 ~~~{.cpp}
2460  struct ns__record record;
2461  soap_read_ns__record(soap, &record);
2462  if (record.ns__derived)
2463  printf("Derived type with name=%s number=%d text=%s value=%s\n",
2464  record.ns__derived->name,
2465  record.ns__derived->number,
2466  record.ns__derived->text,
2467  record.ns__derived->value);
2468  else
2469  printf("Base type with name=%s number=%d\n",
2470  record.name,
2471  record.number);
2472 ~~~
2473 
2474 This example requires the `SOAP_XML_STRICT` mode flag to initialize the `soap`
2475 context to ensure that all required values are present in the deserialized
2476 structures, otherwise the `char*` strings may be NULL since XML validation
2477 constraints are not enforced on the XML input.
2478 
2479 Deeper levels of simulated inheritance are possible, for example:
2480 
2481 ~~~{.cpp}
2482  struct ns__base // a base type
2483  {
2484  char *name 1;
2485  int number 1;
2486  [ struct ns__derived *ns__derived; ] // points to derived type if non-NULL
2487  };
2488  struct ns__derived // extends ns__base with two additional members
2489  {
2490  char *name 1;
2491  int number 1;
2492  char *text 1;
2493  @ char *value 1;
2494  [ struct ns__derived_derived *ns__derived_derived; ] // points to derived_derived type if non-NULL
2495  };
2496  struct ns__derived_derived // extends ns__derived with an additional member
2497  {
2498  char *name 1;
2499  int number 1;
2500  char *text 1;
2501  @ char *value 1;
2502  @ char *type 1;
2503  };
2504 ~~~
2505 
2506 This requires two pointer traversals from the base type `ns__base` via
2507 `ns__derived` to reach `ns__derived_derived`.
2508 
2509 🔝 [Back to table of contents](#)
2510 
2511 ### Volatile classes and structs {#toxsd9-2}
2512 
2513 Classes and structs can be declared `volatile` in the interface header file for
2514 soapcpp2, which only has meaning for the gSOAP tools. This annotation means
2515 that these types are already declared elsewhere in your project's source code
2516 and you do not want soapcpp2 to generate code with a second declaration of
2517 these types.
2518 
2519 For example, `struct tm` is declared in the <i>`time.h`</i> library. You can
2520 make it serializable and include a partial list of data members that you want
2521 to serialize:
2522 
2523 ~~~{.cpp}
2524  volatile struct tm
2525  {
2526  int tm_sec; // seconds (0 - 60)
2527  int tm_min; // minutes (0 - 59)
2528  int tm_hour; // hours (0 - 23)
2529  int tm_mday; // day of month (1 - 31)
2530  int tm_mon; // month of year (0 - 11)
2531  int tm_year; // year - 1900
2532  };
2533 ~~~
2534 
2535 You can declare classes and structs `volatile` for any such types you want to
2536 serialize by only providing the public data members you want to serialize.
2537 
2538 In addition, [colon notation](#toxsd2) is a simple and effective way to bind an
2539 existing class or struct to a schema. For example, you can change the `tm` name
2540 as follows without affecting the code that uses `struct tm` generated by
2541 soapcpp2:
2542 
2543 ~~~{.cpp}
2544  volatile struct ns:tm { ... }
2545 ~~~
2546 
2547 This struct maps to a complexType in the soapcpp2-generated XML schema:
2548 
2549 <div class="alt">
2550 ~~~{.xml}
2551  <complexType name="tm">
2552  <sequence>
2553  <element name="tm-sec" type="xsd:int" minOccurs="1" maxOccurs="1"/>
2554  <element name="tm-min" type="xsd:int" minOccurs="1" maxOccurs="1"/>
2555  <element name="tm-hour" type="xsd:int" minOccurs="1" maxOccurs="1"/>
2556  <element name="tm-mday" type="xsd:int" minOccurs="1" maxOccurs="1"/>
2557  <element name="tm-mon" type="xsd:int" minOccurs="1" maxOccurs="1"/>
2558  <element name="tm-year" type="xsd:int" minOccurs="1" maxOccurs="1"/>
2559  </sequence>
2560  </complexType>
2561 ~~~
2562 </div>
2563 
2564 🔝 [Back to table of contents](#)
2565 
2566 ### Mutable classes and structs {#toxsd9-3}
2567 
2568 Classes and structs can be declared `mutable` with the gSOAP tools. This means
2569 that their definition can be spread out over the source code. This promotes the
2570 concept of a class or struct as a *row of named values*, also known as a *named
2571 tuple*, that can be extended at compile time in your source code with additional
2572 members. Because these types differ from the traditional object-oriented
2573 principles and design concepts of classes and objects, constructors and
2574 destructors cannot be defined (also because we cannot guarantee merging these
2575 into one such that all members will be initialized). A default constructor,
2576 copy constructor, assignment operation, and destructor will be assigned
2577 automatically by soapcpp2.
2578 
2579 ~~~{.cpp}
2580  mutable struct ns__tuple
2581  {
2582  @ std::string id;
2583  };
2584 
2585  mutable struct ns__tuple
2586  {
2587  std::string name;
2588  std::string value;
2589  };
2590 ~~~
2591 
2592 The members are collected into one definition generated by soapcpp2. Members
2593 may be repeated from one definition to another, but only if their associated
2594 types are identical. So, for example, a third extension with a `value` member
2595 with a different type fails:
2596 
2597 ~~~{.cpp}
2598  mutable struct ns__tuple
2599  {
2600  float value; // BAD: value is already declared std::string
2601  };
2602 ~~~
2603 
2604 The `mutable` concept has proven to be very useful when declaring and
2605 collecting SOAP Headers for multiple services, which are collected into one
2606 `struct SOAP_ENV__Header` by the soapcpp2 tool.
2607 
2608 🔝 [Back to table of contents](#)
2609 
2610 ### Default and fixed member values {#toxsd9-4}
2611 
2612 Class and struct data members in C and C++ may be declared with an optional
2613 default initialization value that is provided "inline" with the declaration of
2614 the member:
2615 
2616 ~~~{.cpp}
2617  class ns__record
2618  {
2619  public:
2620  std::string name = "Joe";
2621  ...
2622  };
2623 ~~~
2624 
2625 Alternatively, you can use C++11 default initialization syntax:
2626 
2627 ~~~{.cpp}
2628  class ns__record
2629  {
2630  public:
2631  std::string name { "Joe" };
2632  ...
2633  };
2634 ~~~
2635 
2636 Any member with a primitive type can be initialized in this way.
2637 
2638 These initializations are performed by the default constructor that is added by
2639 soapcpp2 to each class and struct (in C++ only). A constructor is only added
2640 when a default constructor is not already defined with the class declaration.
2641 
2642 You can explicitly (re)initialize an object with these initial values by using
2643 the soapcpp2 auto-generated functions:
2644 
2645 - `void T::soap_default(struct soap*)` for `class T` (C++ only)
2646 
2647 - `void soap_default_T(struct soap*, T*)` for `struct T` (C and C++).
2648 
2649 If `T` is a struct or class that has a `soap` pointer member to a `::soap`
2650 context then this pointer member will be set to the first argument passed to
2651 these functions to initialize their `soap` pointer member.
2652 
2653 Default value initializations can be provided for members that have primitive
2654 types (`bool`, `enum`, `time_t`, numeric and string types).
2655 
2656 Default value initializations of pointer members is permitted, but the effect
2657 is different. To conform to XML schema validation, an attribute member that is
2658 a pointer to a primitive type will be assigned the default value when parsed
2659 from XML. An element member that is a pointer to a primitive type will be
2660 assigned when the element is empty when parsed from XML.
2661 
2662 As of gSOAP 2.8.48 and greater, a fixed value can be assigned with a `==`. A
2663 fixed value is also verified by the parser's validator.
2664 
2665 Default and fixed values for members with or without pointers are best
2666 explained with the following two example fragments.
2667 
2668 A record class with default values for `std::string` (or `std::wstring`)
2669 attributes and elements is declared as follows:
2670 
2671 ~~~{.cpp}
2672  class ns__record_with_default
2673  {
2674  public:
2675  @ std::string a = "A"; // optional XML attribute with default value "A"
2676  @ std::string b 1 = "B"; // required XML attribute with default value "B"
2677  @ std::string *c = "C"; // optional XML attribute with default value "C"
2678  std::string d 0 = "D"; // optional XML element with default value "D"
2679  std::string e = "E"; // required XML element with default value "E"
2680  std::string *f = "F"; // optional XML element with default value "F"
2681  ...
2682  };
2683 ~~~
2684 
2685 Also `std::unique_ptr` and `std::shared_ptr` may be used instead of a regular
2686 pointer to strings.
2687 
2688 With C `char*` (or `const char*`, `const wchar_t*`) strings in a struct, this
2689 becomes:
2690 
2691 ~~~{.cpp}
2692  struct ns__record_with_default
2693  {
2694  @ char* a = "A"; // optional XML attribute with default value "A"
2695  @ char* b 1 = "B"; // required XML attribute with default value "B"
2696  char* e 1 = "E"; // required XML element with default value "E"
2697  char* f = "F"; // optional XML element with default value "F"
2698  ...
2699  };
2700 ~~~
2701 
2702 By contrast to `std::string e`, `char* e` must be marked `1` to make it
2703 required, because pointer members are optional by default.
2704 
2705 Attributes are considered optional by default, unless marked as required with
2706 the occurrence constraint `1`. Elements are considered required unless the
2707 member type is a pointer or if the member is marked optional with occurrence
2708 constraint `0`.
2709 
2710 Instead of default values, fixed values indicate that the attribute or element
2711 must contain that value, and only that value, when provided in XML. A fixed
2712 value is specified with a `==`.
2713 
2714 Attributes with default or fixed values may be omitted in XML. When absent,
2715 the default/fixed value is used at the receiving side, i.e. the deserializer
2716 assigns the default/fixed value when the attribute is absent. Therefore, there
2717 is no need to make attributes with default/fixed values pointer based, because
2718 there is no way to distinguish an omitted attribute from a populated attribute
2719 on the receiving side. The `c` member in the example above can be a
2720 non-pointer for this reason. The wsdl2h tool does not generate pointers for
2721 attributes with default/fixed values.
2722 
2723 Elements with default or fixed values may be optional and the use of
2724 default/fixed values with elements differs from attributes. The default/fixed
2725 value of an element is only used for elements that are empty in the XML payload
2726 received. Omitted optional elements in the XML payload received are simply
2727 absent; no default/fixed value is assigned.
2728 
2729 @note gSOAP 2.8.106 and greater treat `char*` and `wchar_t*` with explicit
2730 default and fixed values differently than previous versions. Versions prior to
2731 2.8.106 assign the default value when the corresponding XML element is absent,
2732 whereas 2.8.106 and greater assign NULL when the XML element is absent, exactly
2733 as documented in this updated version of this document. To revert to the old
2734 behavior, use <b>`soapcpp2 -z4`</b> option <b>`-z4`</b>. The change affects
2735 members `char* f` and `char* l` (see below).
2736 
2737 A record class (can be a struct in C) with fixed values for attributes and
2738 elements is declared as follows:
2739 
2740 ~~~{.cpp}
2741  class ns__record_with_fixed
2742  {
2743  public:
2744  @ std::string g == "G"; // optional XML attribute with fixed value "G"
2745  @ std::string h 1 == "H"; // required XML attribute with fixed value "H"
2746  @ std::string *i == "I"; // optional XML attribute with fixed value "I"
2747  std::string j 0 == "J"; // optional XML element with fixed value "J"
2748  std::string k == "K"; // required XML element with fixed value "K"
2749  std::string *l == "L"; // optional XML element with fixed value "L"
2750  ...
2751  };
2752 ~~~
2753 
2754 With C `char*` (or `const char*`, `const wchar_t*`) strings in a struct, this
2755 becomes:
2756 
2757 ~~~{.cpp}
2758  struct ns__record_with_fixed
2759  {
2760  @ char* g == "G"; // optional XML attribute with fixed value "G"
2761  @ char* h 1 == "H"; // required XML attribute with fixed value "H"
2762  char* k 1 == "K"; // required XML element with fixed value "K"
2763  char* l == "L"; // optional XML element with fixed value "L"
2764  ...
2765  };
2766 ~~~
2767 
2768 The XML schema validation rules for the examples above are as follows:
2769 
2770 Member | Notes
2771 ------ | ---------------------------------------------------------------------
2772 `a` | attribute may appear once; if it does not appear its value is "A", otherwise its value is that given (also note: instantiating `ns__record_with_default` assigns the default value "A")
2773 `b` | has no effect when parsing XML (but note: instantiating `ns__record_with_default` assigns the default value "B")
2774 `c` | attribute may appear once; if it does not appear its value is "C", otherwise its value is that given (also note: instantiating `ns__record_with_default` assigns NULL)
2775 `d` | element may appear once; if it does not appear or if it is empty, its value is "D"; otherwise its value is that given (also note: instantiating `ns__record_with_default` assigns the default value "D")
2776 `e` | has no effect when parsing XML (but note: instantiating `ns__record_with_default` assigns the default value "E")
2777 `f` | element may appear once; if it does not appear it is not provided; if it does appear and it is empty, its value is "F"; otherwise its value is that given (also note: instantiating `ns__record_with_default` assigns NULL)
2778 `g` | attribute may appear once; if it does not appear its value is "G", if it does not appear its value is "G" (also note: instantiating `ns__record_with_fixed` assigns the fixed value "G")
2779 `h` | attribute must appear once, its value must be "H" (also note: instantiating `ns__record_with_fixed` assigns the fixed value "H")
2780 `i` | attribute may appear once; if it does not appear its value is "I", if it does not appear its value is "I" (also note: instantiating `ns__record_with_fixed` assigns NULL)
2781 `j` | element may appear once, if it does not appear it is not provided; if it does appear and it is empty, its value is "J"; if it does appear and it is not empty, its value must be "J" (also note: instantiating `ns__record_with_fixed` assigns the fixed value "J")
2782 `k` | element must appear once, its value must be "K" (also note: instantiating `ns__record_with_fixed` assigns the fixed value "K")
2783 `l` | element may appear once, if it does not appear it is not provided; if it does appear and it is empty, its value is "J"; if it does appear and it is not empty, its value must be "J" (also note: instantiating `ns__record_with_fixed` assigns NULL)
2784 
2785 Members of type `char[N]` (fixed length string) can have default and fixed
2786 values, when <b>`soapcpp2 -b`</b> option <b>`-b`</b> is used. Also `char**`
2787 (pointer to a string) members can have default and fixed values. However,
2788 members of this type will be initialized to NULL. The default/fixed values
2789 will be assigned with the same rules as for `char*` when deserialized from XML.
2790 
2791 @see Section [operations on classes and structs](#toxsd9-14).
2792 
2793 🔝 [Back to table of contents](#)
2794 
2795 ### Attribute members {#toxsd9-5}
2796 
2797 Class and struct data members are declared as XML attributes by annotating
2798 their type with a `@` qualifier:
2799 
2800 ~~~{.cpp}
2801  class ns__record
2802  {
2803  public:
2804  @ std::string name; // required (non-pointer means required)
2805  @ uint64_t SSN; // required (non-pointer means required)
2806  ns__record *spouse; // optional (pointer means minOccurs=0)
2807  };
2808 ~~~
2809 
2810 This class maps to a complexType in the soapcpp2-generated XML schema:
2811 
2812 <div class="alt">
2813 ~~~{.xml}
2814  <complexType name="record">
2815  <sequence>
2816  <element name="spouse" type="ns:record" minOccurs="0" maxOccurs="1" nillable="true"/>
2817  </sequence>
2818  <attribute name="name" type="xsd:string" use="required"/>
2819  <attribute name="SSN" type="xsd:unsignedLong" use="required"/>
2820  </complexType>
2821 ~~~
2822 </div>
2823 
2824 An example XML instance of `ns__record` is:
2825 
2826 <div class="alt">
2827 ~~~{.xml}
2828  <ns:record xmlns:ns="urn:types" name="Joe" SSN="1234567890">
2829  <spouse name="Jane" SSN="1987654320">
2830  </spouse>
2831  </ns:record>
2832 ~~~
2833 </div>
2834 
2835 Attribute data members are restricted to primitive types (`bool`, `enum`,
2836 `time_t`, numeric and string types), `xsd__hexBinary`, `xsd__base64Binary`, and
2837 custom serializers, such as `xsd__dateTime`. Custom serializers for types that
2838 may be used as attributes should define `soap_s2T` and `soap_T2s` functions that
2839 convert values of type `T` to strings and back.
2840 
2841 Attribute data members can be pointers and smart pointers to these types, which
2842 permits attributes to be optional.
2843 
2844 🔝 [Back to table of contents](#)
2845 
2846 ### Backtick XML tags {#toxsd9-5-1}
2847 
2848 The XML tag name of a class/struct member is the name of the member with the
2849 usual XML tag translation, see [colon notation](#toxsd2).
2850 
2851 To override the standard translation of identifier names to XML tag names of
2852 attributes and elements, add the XML tag name in backticks (requires gSOAP
2853 2.8.30 or greater):
2854 
2855 ~~~{.cpp}
2856  class ns__record
2857  {
2858  public:
2859  @ std::string name `full-name`;
2860  @ uint64_t SSN `tax-id`;
2861  ns__record *spouse `married-to`;
2862  };
2863 ~~~
2864 
2865 This class maps to a complexType in the soapcpp2-generated XML schema:
2866 
2867 <div class="alt">
2868 ~~~{.xml}
2869  <complexType name="record">
2870  <sequence>
2871  <element name="married-to" type="ns:record" minOccurs="0" maxOccurs="1"/>
2872  </sequence>
2873  <attribute name="full-name" type="xsd:string" use="required"/>
2874  <attribute name="tax-id" type="xsd:unsignedLong" use="required"/>
2875  </complexType>
2876 ~~~
2877 </div>
2878 
2879 An example XML instance of `ns__record` is:
2880 
2881 <div class="alt">
2882 ~~~{.xml}
2883  <ns:record xmlns:ns="urn:types" full-name="Joe" tax-id="1234567890">
2884  <married-to full-name="Jane" tax-id="1987654320">
2885  </married-to>
2886  </ns:record>
2887 ~~~
2888 </div>
2889 
2890 A backtick XML tag name may contain any non-empty sequence of ASCII and UTF-8
2891 characters except white space and the backtick character. A backtick tag can
2892 be combined with member constraints and default member initializers:
2893 
2894 ~~~{.cpp}
2895  @ uint64_t SSN `tax-id` 0:1 = 999;
2896 ~~~
2897 
2898 🔝 [Back to table of contents](#)
2899 
2900 ### Qualified and unqualified members {#toxsd9-6}
2901 
2902 Class, struct, and union data members are mapped to namespace qualified or
2903 unqualified tag names of local elements and attributes. If a data member has
2904 no prefix then the default form of qualification is applied based on the
2905 element/attribute form that is declared with the XML schema of the class, struct,
2906 or union type. If the member name has a namespace prefix by colon notation,
2907 then the prefix overrules the default (un)qualified form. Therefore,
2908 [colon notation](#toxsd2) is an effective mechanism to control qualification of
2909 tag names of individual members of classes, structs, and unions.
2910 
2911 The XML schema elementFormDefault and attributeFormDefault declarations control
2912 the tag name qualification of local elements and attributes, respectively.
2913 
2914 - "unqualified" indicates that local elements/attributes are not qualified with
2915  the namespace prefix.
2916 
2917 - "qualified" indicates that local elements/attributes must be qualified with
2918  the namespace prefix.
2919 
2920 Individual schema declarations of local elements and attributes may overrule
2921 this by using the form declaration in an XML schema and by using colon notation
2922 to add namespace prefixes to class, struct, and union members in the header
2923 file for soapcpp2.
2924 
2925 Consider for example an `ns__record` class in the `ns` namespace in which local
2926 elements are qualified and local attributes are unqualified by default:
2927 
2928 ~~~{.cpp}
2929  //gsoap ns schema namespace: urn:types
2930  //gsoap ns schema elementForm: qualified
2931  //gsoap ns schema attributeForm: unqualified
2932  class ns__record
2933  {
2934  public:
2935  @ std::string name;
2936  @ uint64_t SSN;
2937  ns__record *spouse;
2938  };
2939 ~~~
2940 
2941 This class maps to a complexType in the soapcpp2-generated XML schema with
2942 targetNamespace "urn:types", elementFormDefault qualified and
2943 attributeFormDefault unqualified:
2944 
2945 <div class="alt">
2946 ~~~{.xml}
2947  <schema targetNamespace="urn:types"
2948  ...
2949  elementFormDefault="qualified"
2950  attributeFormDefault="unqualified"
2951  ... >
2952  <complexType name="record">
2953  <sequence>
2954  <element name="spouse" type="ns:record" minOccurs="0" maxOccurs="1"/>
2955  </sequence>
2956  <attribute name="name" type="xsd:string" use="required"/>
2957  <attribute name="SSN" type="xsd:unsignedLong" use="required"/>
2958  </complexType>
2959  </schema>
2960 ~~~
2961 </div>
2962 
2963 An example XML instance of `ns__record` is:
2964 
2965 <div class="alt">
2966 ~~~{.xml}
2967  <ns:record xmlns:ns="urn:types" name="Joe" SSN="1234567890">
2968  <ns:spouse> name="Jane" SSN="1987654320">
2969  </ns:spouse>
2970  </ns:record>
2971 ~~~
2972 </div>
2973 
2974 Here the root element <i>`<ns:record>`</i> is qualified because it is a root
2975 element of the XML schema with target namespace "urn:types". Its local element
2976 <i>`<ns:spouse>`</i> is namespace qualified because the elementFormDefault of
2977 local elements is qualified. Attributes are unqualified.
2978 
2979 The default namespace (un)qualification of local elements and attributes can be
2980 overruled by adding a prefix to the member name by using colon notation:
2981 
2982 ~~~{.cpp}
2983  //gsoap ns schema namespace: urn:types
2984  //gsoap ns schema elementForm: qualified
2985  //gsoap ns schema attributeForm: unqualified
2986  class ns__record
2987  {
2988  public:
2989  @ std::string ns:name; // 'ns:' qualified
2990  @ uint64_t SSN;
2991  ns__record *:spouse; // ':' unqualified (no prefix)
2992  };
2993 ~~~
2994 
2995 The colon notation for member <i>`ns:name`</i> forces qualification of its attribute
2996 tag in XML. The colon notation for member <i>`:spouse`</i> removes qualification from
2997 its local element tag:
2998 
2999 <div class="alt">
3000 ~~~{.xml}
3001  <schema targetNamespace="urn:types"
3002  ...
3003  elementFormDefault="unqualified"
3004  attributeFormDefault="unqualified"
3005  ... >
3006  <complexType name="record">
3007  <sequence>
3008  <element name="spouse" type="ns:record" minOccurs="0" maxOccurs="1" form="unqualified"/>
3009  </sequence>
3010  <attribute name="name" type="xsd:string" use="required" form="qualified"/>
3011  <attribute name="SSN" type="xsd:unsignedLong" use="required"/>
3012  </complexType>
3013  </schema>
3014 ~~~
3015 </div>
3016 
3017 XML instances of `ns__record` have unqualified spouse elements and qualified
3018 ns:name attributes:
3019 
3020 <div class="alt">
3021 ~~~{.xml}
3022  <ns:record xmlns:ns="urn:types" ns:name="Joe" SSN="1234567890">
3023  <spouse> ns:name="Jane" SSN="1987654320">
3024  </spouse>
3025  </ns:record>
3026 ~~~
3027 </div>
3028 
3029 Members of a class or struct can also be prefixed using the `prefix__name`
3030 convention or using colon notation `prefix:name`. However, this has a
3031 different effect by referring to global (root) elements and attributes, see
3032 [document root element definitions](#toxsd9-7).
3033 
3034 [Backtick XML tags](#toxsd9-5-1) can be used in place of the member name
3035 annotations and will achieve the same effect as described when these tag names
3036 are (un)qualified (requires gSOAP 2.8.30 or greater).
3037 
3038 @note You must declare a target namespace with a `//gsoap ns schema namespace:`
3039 directive to enable the `elementForm` and `attributeForm` directives in order
3040 to generate valid XML schemas with soapcpp2. See [directives](#directives) for
3041 more details.
3042 
3043 🔝 [Back to table of contents](#)
3044 
3045 ### Defining document root elements {#toxsd9-7}
3046 
3047 To define and reference XML document root elements we use type names that start
3048 with an underscore:
3049 
3050 ~~~{.cpp}
3051  class _ns__record
3052 ~~~
3053 
3054 Alternatively, we can use a `typedef` to define a document root element with a
3055 given type:
3056 
3057 ~~~{.cpp}
3058  typedef ns__record _ns__record;
3059 ~~~
3060 
3061 This `typedef` maps to a global root element that is added to the
3062 soapcpp2-generated XML schema:
3063 
3064 <div class="alt">
3065 ~~~{.xml}
3066  <element name="record" type="ns:record"/>
3067 ~~~
3068 </div>
3069 
3070 An example XML instance of `_ns__record` is:
3071 
3072 <div class="alt">
3073 ~~~{.xml}
3074  <ns:record xmlns:ns="urn:types">
3075  <name>Joe</name>
3076  <SSN>1234567890</SSN>
3077  <spouse>
3078  <name>Jane</name>
3079  <SSN>1987654320</SSN>
3080  </spouse>
3081  </ns:record>
3082 ~~~
3083 </div>
3084 
3085 Global-level element/attribute definitions are also referenced and/or added to
3086 the generated XML schema when serializable data members reference these by
3087 their qualified name:
3088 
3089 ~~~{.cpp}
3090  typedef std::string _ns__name 1 : 100;
3091  class _ns__record
3092  {
3093  public:
3094  @ _QName xsi__type; // built-in XSD attribute xsi:type
3095  _ns__name ns__name; // ref to global ns:name element
3096  uint64_t SSN;
3097  _ns__record *spouse;
3098  };
3099 ~~~
3100 
3101 These types map to the following comonents in the soapcpp2-generated XML
3102 schema:
3103 
3104 <div class="alt">
3105 ~~~{.xml}
3106  <simpleType name="name">
3107  <restriction base="xsd:string">
3108  <minLength value="1"/>
3109  <maxLength value="100"/>
3110  </restriction>
3111  </simpleType>
3112  <element name="name" type="ns:name"/>
3113  <complexType name="record">
3114  <sequence>
3115  <element ref="ns:name" minOccurs="1" maxOccurs="1"/>
3116  <element name="SSN" type="xsd:unsignedLong" minOccurs="1" maxOccurs="1"/>
3117  <element name="spouse" type="ns:record" minOccurs="0" maxOccurs="1"/>
3118  </sequence>
3119  <attribute ref="xsi:type" use="optional"/>
3120  </complexType>
3121  <element name="record" type="ns:record"/>
3122 ~~~
3123 </div>
3124 
3125 Use only use qualified member names when their types match the global-level
3126 element types that they refer to. For example:
3127 
3128 ~~~{.cpp}
3129  typedef std::string _ns__name; // global element ns:name of type xsd:string
3130  class _ns__record
3131  {
3132  public:
3133  int ns__name; // BAD: global element ns:name is NOT type int
3134  _ns__record ns__record; // OK: ns:record is a global-level root element
3135  ...
3136  };
3137 ~~~
3138 
3139 Therefore, we recommend to use qualified member names only when necessary to
3140 refer to standard XSD elements and attributes, such as `xsi__type`, and
3141 `xsd__lang`.
3142 
3143 By contrast, colon notation has the desired effect to (un)qualify local tag
3144 names by overruling the default element/attribute namespace qualification, see
3145 [qualified and unqualified members](#toxsd9-6).
3146 
3147 As an alternative to prefixing member names, use the backtick tag (requires
3148 gSOAP 2.8.30 or greater):
3149 
3150 ~~~{.cpp}
3151  typedef std::string _ns__name 1 : 100;
3152  class _ns__record
3153  {
3154  public:
3155  @ _QName t <i>`xsi:type`</i>; // built-in XSD attribute xsi:type
3156  _ns__name s <i>`ns:name`</i>; // ref to global ns:name element
3157  uint64_t SSN;
3158  _ns__record *spouse;
3159  };
3160 ~~~
3161 
3162 🔝 [Back to table of contents](#)
3163 
3164 ### (Smart) pointer members and their occurrence constraints {#toxsd9-8}
3165 
3166 A public pointer-typed data member is serialized by following its (smart)
3167 pointer(s) to the value pointed to. To serialize pointers to dynamic arrays of
3168 data, please see the next section on
3169 [container and array members and their occurrence constraints](#toxsd9-9).
3170 
3171 Pointers that are NULL and smart pointers that are empty are serialized to
3172 produce omitted element and attribute values, unless an element is required
3173 and is nillable (struct/class members marked with `nullptr`) in which case the
3174 element is rendered as an empty element with <i>`xsi:nil="true"`</i>.
3175 
3176 To control the occurrence requirements of pointer-based data members,
3177 occurrence constraints are associated with data members in the form of a range
3178 `minOccurs : maxOccurs`. For non-repeatable (meaning, not a container or array)
3179 data members, there are only three reasonable occurrence constraints:
3180 
3181 - `0:0` means that this element or attribute is prohibited.
3182 
3183 - `0:1` means that this element or attribute is optional.
3184 
3185 - `1:1` means that this element or attribute is required.
3186 
3187 Pointer-based data members have a default `0:1` occurrence constraint, making
3188 them optional, and their XML schema local element/attribute definition is
3189 marked as nillable. Non-pointer data members have a default `1:1` occurence
3190 constraint, making them required.
3191 
3192 A `nullptr` occurrence constraint may be applicable to required elements that
3193 are nillable pointer types, thus `nullptr 1:1`. This indicates that the
3194 element is nillable (can be `NULL` or `nullptr`). A pointer data member that
3195 is explicitly marked as required and nillable with `nullptr 1:1` will be
3196 serialized as an element with an <i>`xsi:nil`</i> attribute, thus effectively
3197 revealing the NULL property of its value.
3198 
3199 @note When elements or attributes are required, then you should properly
3200 populate the C/C++ data to serialize. This avoids serializing C/C++ data into
3201 invalid XML. For example, if a C/C++ struct or class member is required, but
3202 its pointer is NULL, then the serializer will emit an XML element attributed
3203 <i>`xsi:nil`</i>. However, this serialization is not valid if the XML schema
3204 does not permit <i>`xsi:nil`</i>, which is the default. This is valid only
3205 when the XML schema declares the element <i>`nillable="true"`</i>.
3206 
3207 @note When an XML element attributed <i>`xsi:nil`</i> is received, but the
3208 element is required and is not nillable, then an XML validation error is raised
3209 when the mode flag `SOAP_XML_STRICT` is set.
3210 
3211 @note However, when an XML element attributed <i>`xsi:nil`</i> is received,
3212 but the element is optional and is not nillable, then in some cases no
3213 validation errors will be reported, even when the mode flag `SOAP_XML_STRICT`
3214 is set. This is the case when the C/C++ struct or class member is a (smart)
3215 pointer or a string type, which are then set to NULL instead (`std::string` is
3216 set to empty). This is to allow some (legacy) aspects of SOAP/XML encoding
3217 flexibility and has no impact on the data consistency and interoperability with
3218 peer services.
3219 
3220 A non-pointer data member that is explicitly marked as optional with `0:1` will
3221 be set to its default value when no XML value is presented to the deserializer.
3222 A default value can be assigned to a data member that has a primitive type or
3223 is a (smart) pointer to primitive type.
3224 
3225 Consider for example:
3226 
3227 ~~~{.cpp}
3228  class ns__record
3229  {
3230  public:
3231  std::shared_ptr<std::string> name; // optional (pointer means minOccurs=0)
3232  uint64_t SSN 0:1 = 999; // force optional with default 999
3233  ns__record *spouse nullptr 1:1; // force required and nillabe when absent
3234  };
3235 ~~~
3236 
3237 This class maps to a complexType in the soapcpp2-generated XML schema:
3238 
3239 <div class="alt">
3240 ~~~{.xml}
3241  <complexType name="record">
3242  <sequence>
3243  <element name="name" type="xsd:string" minOccurs="0" maxOccurs="1" nillable="true"/>
3244  <element name="SSN" type="xsd:unsignedLong" minOccurs="0" maxOccurs="1" default="999"/>
3245  <element name="spouse" type="ns:record" minOccurs="1" maxOccurs="1" nillable="true"/>
3246  </sequence>
3247  </complexType>
3248 ~~~
3249 </div>
3250 
3251 An example XML instance of `ns__record` with its `name` string value set to
3252 `Joe`, `SSN` set to its default, and `spouse` set to NULL:
3253 
3254 <div class="alt">
3255 ~~~{.xml}
3256  <ns:record xmlns:ns="urn:types" ...>
3257  <name>Joe</name>
3258  <SSN>999</SSN>
3259  <spouse xsi:nil="true"/>
3260  </ns:record>
3261 ~~~
3262 </div>
3263 
3264 @note In general, a smart pointer is simply declared as a `volatile` template
3265 in a interface header file for soapcpp2:
3266 ~~~{.cpp}
3267  volatile template <class T> class NAMESPACE::shared_ptr;
3268 ~~~
3269 
3270 @note The soapcpp2 tool generates code that uses `NAMESPACE::shared_ptr` and
3271 `NAMESPACE::make_shared` to create shared pointers to objects, where
3272 `NAMESPACE` is any valid C++ namespace such as `std` and `boost` if you have
3273 Boost installed.
3274 
3275 🔝 [Back to table of contents](#)
3276 
3277 ### Container and array members and their occurrence constraints {#toxsd9-9}
3278 
3279 Class and struct data member types that are containers `std::deque`,
3280 `std::list`, `std::vector` and `std::set` are serialized as a collection of
3281 the values they contain. You can also serialize dynamic arrays, which is the
3282 alternative for C to store collections of data. Let's start with containers.
3283 
3284 You can use `std::deque`, `std::list`, `std::vector`, and `std::set` containers
3285 by importing:
3286 
3287 ~~~{.cpp}
3288  #import "import/stl.h" // import all containers
3289  #import "import/stldeque.h" // import deque
3290  #import "import/stllist.h" // import list
3291  #import "import/stlvector.h" // import vector
3292  #import "import/stlset.h" // import set
3293 ~~~
3294 
3295 For example, to use a vector data mamber to store names in a record:
3296 
3297 ~~~{.cpp}
3298  #import "import/stlvector.h"
3299  class ns__record
3300  {
3301  public:
3302  std::vector<std::string> names;
3303  uint64_t SSN;
3304  };
3305 ~~~
3306 
3307 To limit the number of names in the vector within reasonable bounds, occurrence
3308 constraints are associated with the container. Occurrence constraints are of
3309 the form `minOccurs : maxOccurs`:
3310 
3311 ~~~{.cpp}
3312  #import "import/stlvector.h"
3313  class ns__record
3314  {
3315  public:
3316  std::vector<std::string> names 1:10;
3317  uint64_t SSN;
3318  };
3319 ~~~
3320 
3321 This class maps to a complexType in the soapcpp2-generated XML schema:
3322 
3323 <div class="alt">
3324 ~~~{.xml}
3325  <complexType name="record">
3326  <sequence>
3327  <element name="name" type="xsd:string" minOccurs="1" maxOccurs="10"/>
3328  <element name="SSN" type="xsd:unsignedLong" minOccurs="1" maxOccurs="1"/>
3329  </sequence>
3330  </complexType>
3331 ~~~
3332 </div>
3333 
3334 @note In general, a container is simply declared as a template in an interface
3335 header file for soapcpp2. All class templates are considered containers
3336 (except when declared `volatile`, see smart pointers). For example,
3337 `std::vector` is declared in <i>`gsoap/import/stlvector.h`</i> as:
3338 ~~~{.cpp}
3339  template <class T> class std::vector;
3340 ~~~
3341 
3342 @note You can define and use your own containers. The soapcpp2 tool generates
3343 code that uses the following members of the `template <typename T> class C`
3344 container:
3345 ~~~{.cpp}
3346  void C::clear()
3347  C::iterator C::begin()
3348  C::const_iterator C::begin() const
3349  C::iterator C::end()
3350  C::const_iterator C::end() const
3351  size_t C::size() const
3352  C::iterator C::insert(C::iterator pos, const T& val)
3353 ~~~
3354 
3355 @note For more details see the example `simple_vector` container with
3356 documentation in the package under <i>`gsoap/samples/template`</i>.
3357 
3358 Because C does not support a container template library, we can use a
3359 dynamically-sized array of values. This array is declared as a size-pointer
3360 pair of members within a struct or class. The array size information is stored
3361 in a special size tag member with the name `__size` or `__sizeX`, where `X` can
3362 be any name, or by an `$int` member to identify the member as a special size
3363 tag:
3364 
3365 ~~~{.cpp}
3366  struct ns__record
3367  {
3368  $ int sizeofnames; // array size
3369  char* *names; // array of char* names
3370  uint64_t SSN;
3371  };
3372 ~~~
3373 
3374 This struct maps to a complexType in the soapcpp2-generated XML schema:
3375 
3376 <div class="alt">
3377 ~~~{.xml}
3378  <complexType name="record">
3379  <sequence>
3380  <element name="name" type="xsd:string" minOccurs="0" maxOccurs="unbounded" nillable="true"/>
3381  <element name="SSN" type="xsd:unsignedLong" minOccurs="1" maxOccurs="1"/>
3382  </sequence>
3383  </complexType>
3384 ~~~
3385 </div>
3386 
3387 To limit the number of names in the array within reasonable bounds, occurrence
3388 constraints are associated with the array size member. Occurrence constraints
3389 are of the form `minOccurs : maxOccurs`:
3390 
3391 ~~~{.cpp}
3392  struct ns__record
3393  {
3394  $ int sizeofnames 1:10; // array size 1..10
3395  char* *names; // array of one to ten char* names
3396  uint64_t SSN;
3397  };
3398 ~~~
3399 
3400 This struct maps to a complexType in the soapcpp2-generated XML schema:
3401 
3402 <div class="alt">
3403 ~~~{.xml}
3404  <complexType name="record">
3405  <sequence>
3406  <element name="name" type="xsd:string" minOccurs="1" maxOccurs="10" nillable="true"/>
3407  <element name="SSN" type="xsd:unsignedLong" minOccurs="1" maxOccurs="1"/>
3408  </sequence>
3409  </complexType>
3410 ~~~
3411 </div>
3412 
3413 Arrays can also be declared as nested elements, similar to SOAP-encoded dynamic arrays, and these arrays can be used with or without SOAP applications. This requires a separate struct or class with the name of the SOAP array, which should not be qualified with a namespace prefix:
3414 
3415 ~~~{.cpp}
3416  struct ArrayOfstring
3417  {
3418  char* *__ptr 1:100; // array of 1..100 strings
3419  int __size; // array size
3420  };
3421  struct ns__record
3422  {
3423  struct ArrayOfstring names; // array of char* names
3424  uint64_t SSN;
3425  };
3426 ~~~
3427 
3428 The `ns__record` struct maps to a complexType that references the <i>`ArrayOfstring`</i> complexType with an sequence of 1 to 100 <i>`item`</i> elements:
3429 
3430 <div class="alt">
3431 ~~~{.xml}
3432  <complexType name="ArrayOfstring">
3433  <sequence>
3434  <element name="item" type="xsd:string" minOccurs="1" maxOccurs="100"/>
3435  </sequence>
3436  </complexType>
3437  <complexType name="record">
3438  <sequence>
3439  <element name="names" type="ns:ArrayOfstring" minOccurs="1" maxOccurs="1"/>
3440  <element name="SSN" type="xsd:unsignedLong" minOccurs="1" maxOccurs="1"/>
3441  </sequence>
3442  </complexType>
3443 ~~~
3444 </div>
3445 
3446 To change the <i>`item`</i> element name in the WSDL, XML schema, and XML messages, use `__ptrName` where `Name` is the name you want to use.
3447 
3448 @note When <b>`soapcpp2 -e`</b> option <b>`-e`</b> is used, the <i>`ArrayOfstring`</i> becomes a SOAP-encoded array for SOAP 1.1/1.2 RPC encoded messaging:
3449 <div class="alt">
3450 ~~~{.xml}
3451  <import namespace="http://schemas.xmlsoap.org/soap/encoding/"/>
3452  <complexType name="ArrayOfstring">
3453  <complexContent>
3454  <restriction base="SOAP-ENC:Array">
3455  <sequence>
3456  <element name="item" type="xsd:string" minOccurs="1" maxOccurs="100"/>
3457  </sequence>
3458  <attribute ref="SOAP-ENC:arrayType" WSDL:arrayType="xsd:string[]"/>
3459  </restriction>
3460  </complexContent>
3461  </complexType>
3462  <complexType name="record">
3463  <sequence>
3464  <element name="names" type="ns:ArrayOfstring" minOccurs="1" maxOccurs="1"/>
3465  <element name="SSN" type="xsd:unsignedLong" minOccurs="1" maxOccurs="1"/>
3466  </sequence>
3467  </complexType>
3468 ~~~
3469 </div>
3470 
3471 Fixed-size arrays can be used to store a fixed number of values:
3472 
3473 ~~~{.cpp}
3474  struct ns__record
3475  {
3476  char* names[10]; // array of 10 char* names
3477  uint64_t SSN;
3478  };
3479 ~~~
3480 
3481 The fixed-size array is similar to a SOAP-encoded array, which can be used with or without SOAP applications. This struct maps to a complexType that references a <i>`Array10Ofstring`</i> complexType with ten <i>`item`</i> elements:
3482 
3483 <div class="alt">
3484 ~~~{.xml}
3485  <complexType name="record">
3486  <sequence>
3487  <element name="names" type="ns:Array10Ofstring" minOccurs="1" maxOccurs="1"/>
3488  <element name="SSN" type="xsd:unsignedLong" minOccurs="1" maxOccurs="1"/>
3489  </sequence>
3490  </complexType>
3491  <complexType name="Array10Ofstring">
3492  <sequence>
3493  <element name="item" type="xsd:string" minOccurs="0" maxOccurs="10"/>
3494  </sequence>
3495  </complexType>
3496 ~~~
3497 </div>
3498 
3499 @note When <b>`soapcpp2 -e`</b> option <b>`-e`</b> is used, the <i>`Array10Ofstring`</i> becomes a SOAP-encoded array for SOAP 1.1/1.2 RPC encoded messaging, see previous note.
3500 
3501 🔝 [Back to table of contents](#)
3502 
3503 ### Sequencing with hidden members {#toxsd9-10}
3504 
3505 A member becomes a hidden XML element, i.e. not visibly rendered in XML, when
3506 its name starts with a double underscore. This makes it possible to sequence a
3507 collection of data members, basically by forming a sequence of elements that
3508 can be optional or repeated together.
3509 
3510 To create a sequence of members that are optional, use a pointer-based hidden
3511 member that is a struct with the collection of members to sequence:
3512 
3513 ~~~{.cpp}
3514  struct ns__record
3515  {
3516  std::string name; // required name
3517  struct __ns__optional
3518  {
3519  uint64_t SSN; // SSN in optional group
3520  std::string phone; // phone number in optional group
3521  } *__optional; // optional group
3522  };
3523 ~~~
3524 
3525 Here we used a hidden struct type `__ns__optional` which starts with a double
3526 underscore, because we do not want to define a new global type for the XML
3527 schema we generate. We just need a unique name for a structure that sequences
3528 the two members.
3529 
3530 This struct maps to a complexType in the soapcpp2-generated XML schema:
3531 
3532 <div class="alt">
3533 ~~~{.xml}
3534  <complexType name="record">
3535  <sequence>
3536  <element name="name" type="xsd:string" minOccurs="1" maxOccurs="1"/>
3537  <sequence minOccurs="0" maxOccurs="1">
3538  <element name="SSN" type="xsd:unsignedLong" minOccurs="1" maxOccurs="1"/>
3539  <element name="phone" type="xsd:string" minOccurs="1" maxOccurs="1"/>
3540  </sequence>
3541  </sequence>
3542  </complexType>
3543 ~~~
3544 </div>
3545 
3546 The `name` member is a required element of the <i>`ns:record`</i> complexType.
3547 The <i>`ns:record`</i> complexType has an optional sequence of `SSN` and
3548 `phone` elements.
3549 
3550 To create repetitions of a sequence of members, use an array as follows:
3551 
3552 ~~~{.cpp}
3553  struct ns__record
3554  {
3555  std::string name; // required name
3556  $ int sizeofarray; // size of group array
3557  struct __ns__array
3558  {
3559  uint64_t SSN; // SSN in group
3560  std::string phone; // phone number in group
3561  } *__array; // group array
3562  };
3563 ~~~
3564 
3565 This struct maps to a complexType in the soapcpp2-generated XML schema:
3566 
3567 <div class="alt">
3568 ~~~{.xml}
3569  <complexType name="record">
3570  <sequence>
3571  <element name="name" type="xsd:string" minOccurs="1" maxOccurs="1"/>
3572  <sequence minOccurs="0" maxOccurs="unbounded">
3573  <element name="SSN" type="xsd:unsignedLong" minOccurs="1" maxOccurs="1"/>
3574  <element name="phone" type="xsd:string" minOccurs="1" maxOccurs="1"/>
3575  </sequence>
3576  </sequence>
3577  </complexType>
3578 ~~~
3579 </div>
3580 
3581 The `name` member is a required element of the <i>`ns:record`</i> complexType.
3582 The <i>`ns:record`</i> complexType has a potentially unbounded sequence of
3583 `SSN` and `phone` elements. You can specify array bounds instead of zero to
3584 unbounded, see [container and array members and their occurrence constraints](#toxsd9-9).
3585 
3586 The XML value space consists of a sequence of SSN and phone elements:
3587 
3588 <div class="alt">
3589 ~~~{.xml}
3590  <ns:record>
3591  <name>numbers</name>
3592  <SSN>1234567890</SSN>
3593  <phone>555-123-4567</phone>
3594  <SSN>1987654320</SSN>
3595  <phone>555-789-1234</phone>
3596  <SSN>2345678901</SSN>
3597  <phone>555-987-6543</phone>
3598  </ns:record>
3599 ~~~
3600 </div>
3601 
3602 🔝 [Back to table of contents](#)
3603 
3604 ### Tagged union members {#toxsd9-11}
3605 
3606 A union member in a class or in a struct cannot be serialized unless a
3607 discriminating *variant selector* member is provided that tells the serializer
3608 which union field to serialize. This effectively creates a *tagged union*.
3609 
3610 The variant selector is associated with the union as a selector-union pair of members.
3611 The variant selector is a member with the name `__union` or `__unionX`, where
3612 `X` can be any name, or by an `$int` member to identify the member as a variant
3613 selector tag:
3614 
3615 ~~~{.cpp}
3616  class ns__record
3617  {
3618  public:
3619  $ int xORnORs; // variant selector with values SOAP_UNION_fieldname
3620  union ns__choice
3621  {
3622  float x;
3623  int n;
3624  char *s;
3625  } u;
3626  std::string name;
3627  };
3628 ~~~
3629 
3630 The variant selector values are auto-generated based on the union name `choice`
3631 and the names of its members `x`, `n`, and `s`:
3632 
3633 - `xORnORs = SOAP_UNION_ns__choice_x` when `u.x` is valid.
3634 
3635 - `xORnORs = SOAP_UNION_ns__choice_n` when `u.n` is valid.
3636 
3637 - `xORnORs = SOAP_UNION_ns__choice_s` when `u.s` is valid.
3638 
3639 - `xORnORs = 0` when none are valid (should only be used with great care,
3640  because XSD validation may fail when content is required but absent).
3641 
3642 This class maps to a complexType with a sequence and choice in the
3643 soapcpp2-generated XML schema:
3644 
3645 <div class="alt">
3646 ~~~{.xml}
3647  <complexType name="record">
3648  <sequence>
3649  <choice>
3650  <element name="x" type="xsd:float" minOccurs="1" maxOccurs="1"/>
3651  <element name="n" type="xsd:int" minOccurs="1" maxOccurs="1"/>
3652  <element name="s" type="xsd:string" minOccurs="0" maxOccurs="1" nillable="true"/>
3653  </choice>
3654  <element name="names" type="xsd:string" minOccurs="1" maxOccurs="1" nillable="true"/>
3655  </sequence>
3656  </complexType>
3657 ~~~
3658 </div>
3659 
3660 A container or dynamic array of a union requires wrapping the variant selector
3661 and union member in a struct:
3662 
3663 ~~~{.cpp}
3664  class ns__record
3665  {
3666  public:
3667  std::vector<
3668  struct ns__data // data with a choice of x, n, or s
3669  {
3670  $ int xORnORs; // variant selector with values SOAP_UNION_fieldname
3671  union ns__choice
3672  {
3673  float x;
3674  int n;
3675  char *s;
3676  } u;
3677  }> data; // vector with data
3678  };
3679 ~~~
3680 
3681 and an equivalent definition with a dynamic array instead of a `std::vector`
3682 (you can use this in C with structs):
3683 
3684 ~~~{.cpp}
3685  class ns__record
3686  {
3687  public:
3688  $ int sizeOfdata; // size of dynamic array
3689  struct ns__data // data with a choice of x, n, or s
3690  {
3691  $ int xORnORs; // variant selector with values SOAP_UNION_fieldname
3692  union ns__choice
3693  {
3694  float x;
3695  int n;
3696  char *s;
3697  } u;
3698  } *data; // points to the data array of length sizeOfdata
3699  };
3700 ~~~
3701 
3702 This maps to two complexTypes in the soapcpp2-generated XML schema:
3703 
3704 <div class="alt">
3705 ~~~{.xml}
3706  <complexType name="data">
3707  <choice>
3708  <element name="x" type="xsd:float" minOccurs="1" maxOccurs="1"/>
3709  <element name="n" type="xsd:int" minOccurs="1" maxOccurs="1"/>
3710  <element name="s" type="xsd:string" minOccurs="0" maxOccurs="1" nillable="true"/>
3711  </choice>
3712  </complexType>
3713  <complexType name="record">
3714  <sequence>
3715  <element name="data" type="ns:data" minOccurs="0" maxOccurs="unbounded"/>
3716  </sequence>
3717  </complexType>
3718 ~~~
3719 </div>
3720 
3721 The XML value space consists of a sequence of item elements each wrapped in an
3722 data element:
3723 
3724 <div class="alt">
3725 ~~~{.xml}
3726  <ns:record xmlns:ns="urn:types" ...>
3727  <data>
3728  <n>123</n>
3729  </data>
3730  <data>
3731  <x>3.1</x>
3732  </data>
3733  <data>
3734  <s>hello</s>
3735  </data>
3736  <data>
3737  <s>world</s>
3738  </data>
3739  </ns:record>
3740 ~~~
3741 </div>
3742 
3743 To remove the wrapping data element, simply rename the wrapping struct to
3744 `__ns__data` and the member to `__data` to make this member invisible to the
3745 serializer. The double underscore prefix naming convention is used for the
3746 struct name and member name. Also use a dynamic array instead of a container
3747 (so you can also use this approach in C with structs):
3748 
3749 ~~~{.cpp}
3750  class ns__record
3751  {
3752  public:
3753  $ int sizeOfdata; // size of dynamic array
3754  struct __ns__data // contains choice of x, n, or s
3755  {
3756  $ int xORnORs; // variant selector with values SOAP_UNION_fieldname
3757  union ns__choice
3758  {
3759  float x;
3760  int n;
3761  char *s;
3762  } u;
3763  } *__data; // points to the data array of length sizeOfdata
3764  };
3765 ~~~
3766 
3767 This maps to a complexType in the soapcpp2-generated XML schema:
3768 
3769 <div class="alt">
3770 ~~~{.xml}
3771  <complexType name="record">
3772  <sequence minOccurs="0" maxOccurs="unbounded">
3773  <choice>
3774  <element name="x" type="xsd:float" minOccurs="1" maxOccurs="1"/>
3775  <element name="n" type="xsd:int" minOccurs="1" maxOccurs="1"/>
3776  <element name="s" type="xsd:string" minOccurs="0" maxOccurs="1" nillable="true"/>
3777  </choice>
3778  </sequence>
3779  </complexType>
3780 ~~~
3781 </div>
3782 
3783 The XML value space consists of a sequence of <i>`<x>`</i>, <i>`<n>`</i>, and/or <i>`<s>`</i>
3784 elements:
3785 
3786 <div class="alt">
3787 ~~~{.xml}
3788  <ns:record xmlns:ns="urn:types" ...>
3789  <n>123</n>
3790  <x>3.1</x>
3791  <s>hello</s>
3792  <s>world</s>
3793  </ns:record>
3794 ~~~
3795 </div>
3796 
3797 Please note that structs, classes, and unions are unnested by soapcpp2 (as in
3798 the C standard of nested structs and unions). Therefore, the `ns__choice`
3799 union in the `ns__record` class is redeclared at the top level despite its
3800 nesting within the `ns__record` class. This means that you will have to choose
3801 a unique name for each nested struct, class, and union.
3802 
3803 🔝 [Back to table of contents](#)
3804 
3805 ### Tagged void pointer members {#toxsd9-12}
3806 
3807 To serialize data pointed to by `void*` requires run-time type information that
3808 tells the serializer what type of data to serialize by means of a *tagged void
3809 pointer*. This type information is stored in a special type tag member of a
3810 struct/class with the name `__type` or `__typeX`, where `X` can be any name, or
3811 alternatively by an `$int` special member of any name as a type tag:
3812 
3813 ~~~{.cpp}
3814  class ns__record
3815  {
3816  public:
3817  $ int typeOfdata; // type tag with values SOAP_TYPE_T
3818  void *data; // points to some data of type T
3819  };
3820 ~~~
3821 
3822 A type tag member has nonzero values `SOAP_TYPE_T` where `T` is the name of a
3823 struct/class or the name of a primitive type, such as `int`, `std__string` (for
3824 `std::string`), `string` (for `char*`).
3825 
3826 This class maps to a complexType with a sequence in the soapcpp2-generated
3827 XML schema:
3828 
3829 <div class="alt">
3830 ~~~{.xml}
3831  <complexType name="record">
3832  <sequence>
3833  <element name="data" type="xsd:anyType" minOccurs="0" maxOccurs="1"/>
3834  </sequence>
3835  </complexType>
3836 ~~~
3837 </div>
3838 
3839 The XML value space consists of the XML value space of the type with the
3840 addition of an <i>`xsi:type`</i> attribute to the enveloping element:
3841 
3842 <div class="alt">
3843 ~~~{.xml}
3844  <ns:record xmlns:ns="urn:types" ...>
3845  <data xsi:type="xsd:int">123</data>
3846  </ns:record>
3847 ~~~
3848 </div>
3849 
3850 This <i>`xsi:type`</i> attribute is important for the receiving end to distinguish
3851 the type of data to instantiate. The receiver cannot deserialize the data
3852 without an <i>`xsd:type`</i> attribute.
3853 
3854 You can find the `SOAP_TYPE_T` name of each serializable type in the
3855 auto-generated <i>`soapStub.h`</i> file.
3856 
3857 Also all serializable C++ classes have a virtual `int T::soap_type()` member
3858 that returns their `SOAP_TYPE_T` value that you can use.
3859 
3860 When the `void*` pointer is NULL or when `typeOfdata` is zero, the data is not
3861 serialized.
3862 
3863 A container or dynamic array of `void*` pointers to <i>`xsd:anyType`</i> data
3864 requires wrapping the type tag and `void*` members in a struct:
3865 
3866 ~~~{.cpp}
3867  class ns__record
3868  {
3869  public:
3870  std::vector<
3871  struct ns__data // data with an xsd:anyType item
3872  {
3873  $ int typeOfitem; // type tag with values SOAP_TYPE_T
3874  void *item; // points to some item of type T
3875  }> data; // vector with data
3876  };
3877 ~~~
3878 
3879 and an equivalent definition with a dynamic array instead of a `std::vector`
3880 (you can use this in C with structs):
3881 
3882 ~~~{.cpp}
3883  class ns__record
3884  {
3885  public:
3886  $ int sizeOfdata; // size of dynamic array
3887  struct ns__data // data with an xsd:anyType item
3888  {
3889  $ int typeOfitem; // type tag with values SOAP_TYPE_T
3890  void *item; // points to some item of type T
3891  } *data; // points to the data array of length sizeOfdata
3892  };
3893 ~~~
3894 
3895 This maps to two complexTypes in the soapcpp2-generated XML schema:
3896 
3897 <div class="alt">
3898 ~~~{.xml}
3899  <complexType name="data">
3900  <sequence>
3901  <element name="item" type="xsd:anyType" minOccurs="1" maxOccurs="1" nillable="true"/>
3902  </sequence>
3903  </complexType>
3904  <complexType name="record">
3905  <sequence>
3906  <element name="data" type="ns:data" minOccurs="0" maxOccurs="unbounded"/>
3907  </sequence>
3908  </complexType>
3909 ~~~
3910 </div>
3911 
3912 The XML value space consists of a sequence of item elements each wrapped in a
3913 data element:
3914 
3915 <div class="alt">
3916 ~~~{.xml}
3917  <ns:record xmlns:ns="urn:types" ...>
3918  <data>
3919  <item xsi:type="xsd:int">123</item>
3920  </data>
3921  <data>
3922  <item xsi:type="xsd:double">3.1</item>
3923  </data>
3924  <data>
3925  <item xsi:type="xsd:string">abc</item>
3926  </data>
3927  </ns:record>
3928 ~~~
3929 </div>
3930 
3931 To remove the wrapping data elements, simply rename the wrapping struct and
3932 member to `__data` to make this member invisible to the serializer with the
3933 double underscore prefix naming convention. Also use a dynamic array instead
3934 of a container (you can use this in C with structs):
3935 
3936 ~~~{.cpp}
3937  class ns__record
3938  {
3939  public:
3940  $ int sizeOfdata; // size of dynamic array
3941  struct __data // contains xsd:anyType item
3942  {
3943  $ int typeOfitem; // type tag with values SOAP_TYPE_T
3944  void *item; // points to some item of type T
3945  } *__data; // points to the data array of length sizeOfdata
3946  };
3947 ~~~
3948 
3949 This maps to a complexType in the soapcpp2-generated XML schema:
3950 
3951 <div class="alt">
3952 ~~~{.xml}
3953  <complexType name="record">
3954  <sequence minOccurs="0" maxOccurs="unbounded">
3955  <element name="item" type="xsd:anyType" minOccurs="1" maxOccurs="1"/>
3956  </sequence>
3957  </complexType>
3958 ~~~
3959 </div>
3960 
3961 The XML value space consists of a sequence of data elements:
3962 
3963 <div class="alt">
3964 ~~~{.xml}
3965  <ns:record xmlns:ns="urn:types" ...>
3966  <item xsi:type="xsd:int">123</item>
3967  <item xsi:type="xsd:double">3.1</item>
3968  <item xsi:type="xsd:string">abc</item>
3969  </ns:record>
3970 ~~~
3971 </div>
3972 
3973 Again, please note that structs, classes, and unions are unnested by soapcpp2
3974 (as in the C standard of nested structs and unions). Therefore, the `__data`
3975 struct in the `ns__record` class is redeclared at the top level despite its
3976 nesting within the `ns__record` class. This means that you will have to choose
3977 a unique name for each nested struct, class, and union.
3978 
3979 @see Section [XSD type bindings](#typemap2).
3980 
3981 🔝 [Back to table of contents](#)
3982 
3983 ### Adding get and set methods {#toxsd9-13}
3984 
3985 A public `get` method may be added to a class or struct, which will be
3986 triggered by the deserializer. This method will be invoked right after the
3987 instance is populated by the deserializer. The `get` method can be used to
3988 update or verify deserialized content. It should return `SOAP_OK` or set
3989 `soap::error` to a nonzero error code and return it.
3990 
3991 A public `set` method may be added to a class or struct, which will be
3992 triggered by the serializer. The method will be invoked just before the
3993 instance is serialized. Likewise, the `set` method should return `SOAP_OK` or
3994 set set `soap::error` to a nonzero error code and return it.
3995 
3996 For example, adding a `set` and `get` method to a class declaration:
3997 
3998 ~~~{.cpp}
3999  class ns__record
4000  {
4001  public:
4002  int set(struct soap*); // triggered before serialization
4003  int get(struct soap*); // triggered after deserialization
4004  ...
4005  };
4006 ~~~
4007 
4008 To add these and othe rmethods to classes and structs with wsdl2h and
4009 <i>`typemap.dat`</i>, please see [class/struct member additions](#typemap3).
4010 
4011 🔝 [Back to table of contents](#)
4012 
4013 ### Operations on classes and structs {#toxsd9-14}
4014 
4015 The following functions/macros are generated by soapcpp2 for each type `T`,
4016 which should make it easier to send, receive, and copy XML data in C and in
4017 C++:
4018 
4019 - `int soap_write_T(struct soap*, T*)` writes an instance of `T` to a file via
4020  file descriptor `int soap::sendfd)` or to a stream via `std::ostream
4021  *soap::os` (C++ only) or saves into a NUL-terminated string by setting
4022  `const char **soap::os` to a string pointer to be set (C only). Returns
4023  `SOAP_OK` on success or an error code, also stored in `soap::error`.
4024 
4025 - `int soap_read_T(struct soap*, T*)` reads an instance of `T` from a file via
4026  file descriptor `int soap::recvfd)` or from a stream via `std::istream
4027  *soap::is` (C++ only) or reads from a NUL-termianted string `const char
4028  *soap::is` (C only). Returns `SOAP_OK` on success or an error code, also
4029  stored in `soap::error`.
4030 
4031 - `void soap_default_T(struct soap*, T*)` sets an instance `T` to its default
4032  value, resetting members of a struct to their initial values (for classes we
4033  use method `T::soap_default`, see below). If `T` is a struct that has a
4034  `soap` pointer member to a `::soap` context then this pointer member will be
4035  set to the first argument passed to this function to initialize its `soap`
4036  pointer member.
4037 
4038 - `T * soap_dup_T(struct soap*, T *dst, const T *src)` (requires <b>`soapcpp2 -Ec`</b>)
4039  deep copy `src` into `dst`, replicating all deep cycles and shared pointers
4040  when a managing `soap` context is provided as argument. When `dst` is NULL,
4041  allocates space for `dst` and returns a pointer to the allocated copy. Deep
4042  copy results in a tree when the `soap` context is NULL, but the presence of
4043  deep cycles will lead to non-termination. Use flag `SOAP_XML_TREE` with
4044  managing context to copy into a tree without cycles and pointers to shared
4045  objects. Returns `dst` or allocated copy when `dst` is NULL.
4046 
4047 - `void soap_del_T(const T*)` (requires <b>`soapcpp2 -Ed`</b>) deletes all
4048  heap-allocated members of this object by deep deletion ONLY IF this object
4049  and all of its (deep) members are not managed by a `soap` context AND the deep
4050  structure is a tree (no cycles and co-referenced objects by way of multiple
4051  (non-smart) pointers pointing to the same data). Can be safely used after
4052  `T * soap_dup_T(NULL, NULL, const T*)` to delete the deep copy returned.
4053  Does not delete the object itself.
4054 
4055 When in C++ mode, soapcpp2 tool adds several methods to classes in addition to
4056 adding a default constructor and destructor (when these were not explicitly
4057 declared).
4058 
4059 The public methods added to a class `T`:
4060 
4061 - `virtual int T::soap_type(void)` returns a unique type ID (`SOAP_TYPE_T`).
4062  This numeric ID can be used to distinguish base from derived instances.
4063 
4064 - `virtual void T::soap_default(struct soap*)` sets all data members to
4065  default values. If class `T` has a `soap` pointer member to a `::soap`
4066  context then this pointer member will be set to the argument passed to this
4067  function to initialize its `soap` pointer member.
4068 
4069 - `virtual void T::soap_serialize(struct soap*) const` serializes object to
4070  prepare for SOAP 1.1/1.2 encoded output (or with `SOAP_XML_GRAPH`) by
4071  analyzing its (cyclic) structures.
4072 
4073 - `virtual int T::soap_put(struct soap*, const char *tag, const char *type) const`
4074  emits object in XML, compliant with SOAP 1.1 encoding style, return error
4075  code or `SOAP_OK`. Requires `soap_begin_send(soap)` and
4076  `soap_end_send(soap)`.
4077 
4078 - `virtual int T::soap_out(struct soap*, const char *tag, int id, const char *type) const`
4079  emits object in XML, with tag and optional id attribute and <i>`xsi:type`</i>,
4080  return error code or `SOAP_OK`. Requires `soap_begin_send(soap)` and
4081  `soap_end_send(soap)`.
4082 
4083 - `virtual void * T::soap_get(struct soap*, const char *tag, const char *type)`
4084  Get object from XML, compliant with SOAP 1.1 encoding style, return pointer
4085  to object or NULL on error. Requires `soap_begin_recv(soap)` and
4086  `soap_end_recv(soap)`.
4087 
4088 - `virtual void *soap_in(struct soap*, const char *tag, const char *type)`
4089  Get object from XML, with matching tag and type (NULL matches any tag and
4090  type), return pointer to object or NULL on error. Requires
4091  `soap_begin_recv(soap)` and `soap_end_recv(soap)`
4092 
4093 - `virtual T * T::soap_alloc(void) const` returns a new object of type `T`,
4094  default initialized and not managed by a `soap` context.
4095 
4096 - `virtual T * T::soap_dup(struct soap*) const` (requires <b>`soapcpp2 -Ec`</b>)
4097  returns a duplicate of this object by deep copying, replicating all deep
4098  cycles and shared pointers when a managing `soap` context is provided as
4099  argument. Deep copy is a tree when argument is NULL, but the presence of
4100  deep cycles will lead to non-termination. Use flag `SOAP_XML_TREE` with the
4101  managing context to copy into a tree without cycles and pointers to shared
4102  objects.
4103 
4104 - `virtual void T::soap_del() const` (rquires <b>`soapcpp2 -Ed`</b>) deletes all
4105  heap-allocated members of this object by deep deletion ONLY IF this object
4106  and all of its (deep) members are not managed by a `soap` context AND the deep
4107  structure is a tree (no cycles and co-referenced objects by way of multiple
4108  (non-smart) pointers pointing to the same data). Can be safely used after
4109  `soap_dup(NULL)` to delete the deep copy. Does not delete the object itself.
4110 
4111 Also, there are four variations of `soap_new_T` for
4112 class/struct/template type `T` that soapcpp2 auto-generates to create instances
4113 on a context-managed heap:
4114 
4115 - `T * soap_new_T(struct soap*)` returns a new instance of `T` with default data
4116  member initializations that are set with the soapcpp2 auto-generated `void
4117  T::soap_default(struct soap*)` method), but ONLY IF the soapcpp2
4118  auto-generated default constructor is used that invokes `soap_default()` and
4119  was not replaced by a user-defined default constructor.
4120 
4121 - `T * soap_new_T(struct soap*, int n)` returns an array of `n` new instances of
4122  `T`. Similar to the above, instances are initialized.
4123 
4124 - `T * soap_new_req_T(struct soap*, ...)` returns a new instance of `T` and sets
4125  the required data members to the values specified in `...`. The required data
4126  members are those with nonzero minOccurs, see the subsections on
4127  [(smart) pointer members and their occurrence constraints](#toxsd9-8) and
4128  [container and array members and their occurrence constraints](#toxsd9-9).
4129 
4130 - `T * soap_new_set_T(struct soap*, ...)` returns a new instance of `T` and sets
4131  the public/serializable data members to the values specified in `...`.
4132 
4133 The above functions can be invoked with a NULL `soap` context, but we will be
4134 responsible to use `delete T` to remove this instance from the unmanaged heap.
4135 
4136 The allocation functions return NULL when memory allocation failed.
4137 
4138 🔝 [Back to table of contents](#)
4139 
4140 Special classes and structs {#toxsd10}
4141 ---------------------------
4142 
4143 The following applies to both structs and classes. The examples show classes
4144 in C++. For C, use structs and omit the C++ features. Structs also require
4145 the use of the `struct` keyword, otherwise soapcpp2 will throw a syntax error.
4146 
4147 ### SOAP-encoded arrays {#toxsd10-1}
4148 
4149 A class or struct with the following layout is a one-dimensional SOAP-encoded
4150 array type:
4151 
4152 ~~~{.cpp}
4153  class ArrayOfT
4154  {
4155  public:
4156  T *__ptr; // array pointer
4157  int __size; // array size
4158  };
4159 ~~~
4160 
4161 where `T` is the array element type. A multidimensional SOAP Array is:
4162 
4163 ~~~{.cpp}
4164  class ArrayOfT
4165  {
4166  public:
4167  T *__ptr; // array pointer
4168  int __size[N]; // array size of each dimension
4169  };
4170 ~~~
4171 
4172 where `N` is the constant number of dimensions. The pointer points to an array
4173 of `__size[0]*__size[1]* ... * __size[N-1]` elements.
4174 
4175 This maps to a complexType restriction of SOAP-ENC:Array in the
4176 soapcpp2-generated XML schema:
4177 
4178 <div class="alt">
4179 ~~~{.xml}
4180  <complexType name="ArrayOfT">
4181  <complexContent>
4182  <restriction base="SOAP-ENC:Array">
4183  <sequence>
4184  <element name="item" type="T" minOccurs="0" maxOccurs="unbounded" nillable="true"/>
4185  </sequence>
4186  <attribute ref="SOAP-ENC:arrayType" WSDL:arrayType="ArrayOfT[]"/>
4187  </restriction>
4188  </complexContent>
4189  </complexType>
4190 ~~~
4191 </div>
4192 
4193 The name of the class can be arbitrary. We often use `ArrayOfT` without a
4194 prefix to distinguish arrays from other classes and structs.
4195 
4196 With SOAP 1.1 encoding, an optional offset member can be added that controls
4197 the start of the index range for each dimension:
4198 
4199 ~~~{.cpp}
4200  class ArrayOfT
4201  {
4202  public:
4203  T *__ptr; // array pointer
4204  int __size[N]; // array size of each dimension
4205  int __offset[N]; // array offsets to start each dimension
4206  };
4207 ~~~
4208 
4209 For example, we can define a matrix of floats as follows:
4210 
4211 ~~~{.cpp}
4212  class Matrix
4213  {
4214  public:
4215  double *__ptr;
4216  int __size[2];
4217  };
4218 ~~~
4219 
4220 The following code populates the matrix and serializes it in XML:
4221 
4222 ~~~{.cpp}
4223  soap *soap = soap_new1(SOAP_XML_INDENT);
4224  Matrix A;
4225  double a[6] = { 1, 2, 3, 4, 5, 6 };
4226  A.__ptr = a;
4227  A.__size[0] = 2;
4228  A.__size[1] = 3;
4229  soap_write_Matrix(soap, &A);
4230 ~~~
4231 
4232 Matrix A is serialized as an array with 2x3 values:
4233 
4234 <div class="alt">
4235 ~~~{.xml}
4236  <SOAP-ENC:Array SOAP-ENC:arrayType="xsd:double[2,3]" ...>
4237  <item>1</item>
4238  <item>2</item>
4239  <item>3</item>
4240  <item>4</item>
4241  <item>5</item>
4242  <item>6</item>
4243  </SOAP-ENC:Array>
4244 ~~~
4245 </div>
4246 
4247 🔝 [Back to table of contents](#)
4248 
4249 ### XSD hexBinary and base64Binary types {#toxsd10-2}
4250 
4251 A special case of a one-dimensional array is used to define <i>`xsd:hexBinary`</i> and
4252 <i>`xsd:base64Binary`</i> types when the pointer type is `unsigned char`:
4253 
4254 ~~~{.cpp}
4255  class xsd__hexBinary
4256  {
4257  public:
4258  unsigned char *__ptr; // points to raw binary data
4259  int __size; // size of data
4260  };
4261 ~~~
4262 
4263 and
4264 
4265 ~~~{.cpp}
4266  class xsd__base64Binary
4267  {
4268  public:
4269  unsigned char *__ptr; // points to raw binary data
4270  int __size; // size of data
4271  };
4272 ~~~
4273 
4274 To create a new binary type, use either one of the following three forms that
4275 declare a new `ns__binary` type that is a <i>`simpleType`</i> restriction of
4276 <i>`xsd:base64Binary`</i>:
4277 
4278 ~~~{.cpp}
4279  typedef xsd__base64Binary ns__binary;
4280 ~~~
4281 ~~~{.cpp}
4282  class ns__binary : public xsd__base64Binary
4283  {
4284  ... // attribute members (@) and class methods
4285  };
4286 ~~~
4287 ~~~{.cpp}
4288  class ns__binary
4289  {
4290  public:
4291  unsigned char *__ptr; // points to raw binary data
4292  int __size; // size of data
4293  ... // attribute members (@) and class methods (optional)
4294  };
4295 ~~~
4296 
4297 Here, `xsd__base64Binary` is reused in the first two cases, where
4298 `xsd__base64Binary` is declared as shown above.
4299 
4300 @see [DIME/MIME/MTOM attachment binary types](#toxsd10-3)
4301 
4302 🔝 [Back to table of contents](#)
4303 
4304 ### DIME/MIME/MTOM attachment binary types {#toxsd10-3}
4305 
4306 A class or struct with a binary content layout can be extended to support
4307 attachments. The following struct or class type can be used as DIME, MIME, and
4308 MTOM attachment and also be used for <i>`xsd:base64Binary`</i> type values:
4309 
4310 ~~~{.cpp}
4311  class xsd__base64Binary
4312  {
4313  public:
4314  unsigned char *__ptr; // points to raw binary data
4315  int __size; // size of data
4316  char *id; // NULL to generate an id, or set to a unique UUID
4317  char *type; // MIME type of the data
4318  char *options; // optional description of MIME attachment
4319  };
4320 ~~~
4321 
4322 When the `id`, `type`, or `options` members are non-NULL, an attachment will be
4323 used instead of base64 XML content. DIME attachments are the default. To
4324 switch to MIME use the `SOAP_ENC_MIME` context flag. To switch to MTOM use the
4325 `SOAP_ENC_MTOM` context flag.
4326 
4327 MTOM is typically used with XOP <i>`<xop:Include>`</i> elements, which is
4328 preferred and declared as follows:
4329 
4330 ~~~{.cpp}
4331  //gsoap xop schema import: http://www.w3.org/2004/08/xop/include
4332  class _xop__Include
4333  {
4334  public:
4335  unsigned char *__ptr; // points to raw binary data
4336  int __size; // size of data
4337  char *id; // NULL to generate an id, or set to a unique UUID
4338  char *type; // MIME type of the data
4339  char *options; // optional description of MIME attachment
4340  };
4341 ~~~
4342 
4343 Attachments are beyond the scope of this article. See the
4344 [gSOAP user guide.](../../guide/html/index.html) for more details.
4345 
4346 🔝 [Back to table of contents](#)
4347 
4348 ### Wrapper class/struct with simpleContent {#toxsd10-4}
4349 
4350 A class or struct with the following layout is a complexType that wraps
4351 simpleContent:
4352 
4353 ~~~{.cpp}
4354  class ns__simple
4355  {
4356  public:
4357  T __item; // primitive type for the simpleContent
4358  ... // attribute members (@) and class methods (optional)
4359  };
4360 ~~~
4361 
4362 The type `T` is a primitive type (`bool`, `enum`, `time_t`, numeric and string
4363 types), `xsd__hexBinary`, `xsd__base64Binary`, and custom serializers, such as
4364 `xsd__dateTime`.
4365 
4366 This maps to a complexType with simpleContent in the soapcpp2-generated XML
4367 schema:
4368 
4369 <div class="alt">
4370 ~~~{.xml}
4371  <complexType name="simple">
4372  <simpleContent>
4373  <extension base="T"/>
4374  </simpleContent>
4375  </complexType>
4376 ~~~
4377 </div>
4378 
4379 A wrapper class/struct may include any number of members that are declared as
4380 attributes with `@`, which should be placed after the `__item` member.
4381 
4382 🔝 [Back to table of contents](#)
4383 
4384 ### DOM anyType and anyAttribute {#toxsd10-5}
4385 
4386 Use of a DOM is optional and enabled by `#import "dom.h"` to use the DOM
4387 `xsd__anyType` element node and `xsd__anyAttribute` attribute node:
4388 
4389 ~~~{.cpp}
4390  #import "dom.h"
4391 
4392  class ns__record
4393  {
4394  public:
4395  @ xsd__anyAttribute attributes; // optional DOM attributes
4396  xsd__anyType *name; // optional DOM element (pointer means minOccurs=0)
4397  xsd__anyType address; // required DOM element (minOccurs=1)
4398  xsd__anyType email 0; // optional DOM element (minOccurs=0)
4399  ... // other members
4400  };
4401 ~~~
4402 
4403 where `name` contains XML stored in a DOM node set and `attributes` is a list
4404 of all visibly rendered attributes. The name `attributes` is arbitrary and any
4405 name will suffice.
4406 
4407 You should place the `xsd__anyType` members at the end of the struct or class.
4408 This ensures that the DOM members are populated last as a "catch all". A
4409 member name starting with double underscore is a wildcard member. These
4410 members are placed at the end of a struct or class automatically by soapcpp2.
4411 
4412 An `#import "dom.h"` import is automatically added by <b>`wsdl2h -d`</b> with
4413 option <b>`-d`</b> to bind <i>`xsd:anyType`</i> to DOM nodes, and also to
4414 populate <i>`xsd:any`</i>, <i>`xsd:anyAttribute`</i> and <i>`xsd:mixed`</i> XML
4415 content:
4416 
4417 ~~~{.cpp}
4418  #import "dom.h"
4419 
4420  class ns__record
4421  {
4422  public:
4423  @ xsd__anyAttribute __anyAttribute; // optional DOM attributes
4424  std::vector<xsd__anyType> __any 0; // optional DOM elements (minOccurs=0)
4425  xsd__anyType __mixed 0; // optional mixed content (minOccurs=0)
4426  ... // other members
4427  };
4428 ~~~
4429 
4430 where the members prefixed with `__` are "invisible" to the XML parser, meaning
4431 that these members are not bound to XML tag names.
4432 
4433 In C you can use a dynamic arrary instead of `std::vector`:
4434 
4435 ~~~{.cpp}
4436  #import "dom.h"
4437 
4438  struct ns__record
4439  {
4440  @ xsd__anyAttribute __anyAttribute; // optional DOM attributes
4441  $ int __sizeOfany; // size of the array
4442  xsd__anyType *__any; // optional DOM elements (pointer means minOccurs=0)
4443  xsd__anyType __mixed 0; // optional mixed content (minOccurs=0)
4444  ... // other members
4445  };
4446 ~~~
4447 
4448 Classes can inherit DOM, which enables full use of polymorphism with one base
4449 DOM class:
4450 
4451 ~~~{.cpp}
4452  #import "dom.h"
4453 
4454  class ns__record : public xsd__anyType
4455  {
4456  public:
4457  std::vector<xsd__anyType*> array; // array of objects of any class
4458  ... // other members
4459  };
4460 ~~~
4461 
4462 This permits an `xsd__anyType` pointer to refer to a derived class such as
4463 `ns__record`, which will be serialized with an <i>`xsi:type`</i> attribute that is
4464 set to "ns:record". The <i>`xsi:type`</i> attributes add the necessary type information
4465 to distinguish the XML content from the DOM base type. This is important for
4466 the receiving end: without <i>`xsd:type`</i> attributes with type names, only base DOM
4467 objects are recognized and instantiated.
4468 
4469 Because C lacks object-oriented programming concepts such as class inheritance
4470 and polymorphism, you should consider using [derived types in C and C++](#toxsd9-1-1).
4471 
4472 An alternative is to use the special [tagged void pointer members](#toxsd9-12)
4473 to serialize data pointed to by a `void*` member, which can be any serializable
4474 type, such as derived types. This approach uses <i>`xsi:type`</i> attributes
4475 to identify the type of value serialized.
4476 
4477 To ensure that wsdl2h generates pointer-based `xsd__anyType` DOM nodes with
4478 <b>`wsdl2h -d`</b> using option <b>`-d`</b> for <i>`xsd:any`</i>, add the
4479 following line to <i>`typemap.dat`</i>:
4480 
4481  xsd__any = | xsd__anyType*
4482 
4483 This lets wsdl2h produce class/struct members and containers with
4484 `xsd__anyType*` for <i>`xsd:any`</i> instead of `xsd__anyType`. To just force all
4485 <i>`xsd:anyType`</i> uses to be pointer-based, declare in <i>`typemap.dat`</i>:
4486 
4487  xsd__anyType = | xsd__anyType*
4488 
4489 If you use <b>`wsdl2h -d -p`</b> using options <b>`-d`</b> and <b>`-p`</b> then
4490 every class will inherit DOM as shown above. Without option `-d`, an
4491 `xsd__anyType` type is generated to serve as the root type in the type
4492 hierarchy:
4493 
4494 ~~~{.cpp}
4495  class xsd__anyType { _XML __item; struct soap *soap; };
4496 
4497  class ns__record : public xsd__anyType
4498  {
4499  ...
4500  };
4501 ~~~
4502 
4503 where the `_XML __item` member holds any XML content as a literal XML string.
4504 
4505 To use the DOM API, compile <i>`dom.c`</i> (or <i>`dom.cpp`</i> for C++), or
4506 link the gSOAP library with <b>`-lgsoapssl`</b> (or <b>`-lgsoapssl++`</b> for C++).
4507 
4508 @see Documentation of [XML DOM and XPath](http://www.genivia.com/doc/dom/html)
4509 for more details.
4510 
4511 🔝 [Back to table of contents](#)
4512 
4513 Directives {#directives}
4514 ==========
4515 
4516 You can use `//gsoap` directives in the interface header file with the data
4517 binding interface for soapcpp2. These directives are used to configure the
4518 code generated by soapcpp2 by declaring various. properties of Web services
4519 and XML schemas. When using the wsdl2h tool, you will notice that wsdl2h
4520 generates directives automatically based on the WSDL and XSD input.
4521 
4522 Service directives are applicable to service and operations described by WSDL.
4523 Schema directives are applicable to types, elements, and attributes defined by
4524 XML schemas.
4525 
4526 🔝 [Back to table of contents](#)
4527 
4528 Service directives {#directives-1}
4529 ------------------
4530 
4531 A service directive must start at a new line and is of the form:
4532 
4533 ~~~{.cpp}
4534  //gsoap <prefix> service <property>: <value>
4535 ~~~
4536 
4537 where `<prefix>` is the XML namespace prefix of a service binding. The
4538 `<property>` and `<value>` fields are one of the following:
4539 
4540 property | value
4541 --------------- | -----
4542 `name` | name of the service, optionally followed by text describing the service
4543 `namespace` | URI of the WSDL targetNamespace
4544 `documentation` | text describing the service (see also the `name` property), multiple permitted
4545 `doc` | an alias for the `documentation` property
4546 `style` | `document` (default) SOAP messaging style or `rpc` for SOAP RPC
4547 `encoding` | `literal` (default), `encoded` for SOAP encoding, or a custom URI
4548 `protocol` | specifies SOAP or REST, see below
4549 `port` | URL of the service endpoint, usually an http or https address, to use in the WSDL definitions/service/port/address/\@location
4550 `location` | an alias for the `port` property
4551 `endpoint` | an alias for the `port` property
4552 `transport` | URI declaration of the transport, usually `http://schemas.xmlsoap.org/soap/http`
4553 `definitions` | name of the WSDL definitions/\@name
4554 `type` | name of the WSDL definitions/portType/\@name (WSDL2.0 interface/\@name)
4555 `portType` | an alias for the `type` property (`portType` follows SOAP 1.1 naming conventions)
4556 `interface` | an alias for the `type` property (`interface` follows SOAP 1.2 naming conventions)
4557 `binding` | name of the WSDL definitions/binding/\@name
4558 `portName` | name of the WSDL definitions/service/port/\@name
4559 `executable` | name of the "executable" to use in the WSDL definitions/service/port/address/\@location
4560 
4561 The service `name` and `namespace` properties are required in order to generate
4562 a valid WSDL with soapcpp2. The other properties are optional.
4563 
4564 The `style` and `encoding` property defaults are changed with
4565 <b>`soapcpp2 -e`</b> option <b>`-e`</b> to `rpc` and `encoded`, respectively.
4566 
4567 The `protocol` property is `SOAP` by default (SOAP 1.1). Protocol property
4568 values are:
4569 
4570 protocol value | description
4571 -------------- | -----------
4572 `SOAP` | SOAP transport, supporting both SOAP 1.1 and 1.2
4573 `SOAP1.1` | SOAP 1.1 transport (same as `soapcpp2 -1`)
4574 `SOAP1.2` | SOAP 1.2 transport (same as `soapcpp2 -2`)
4575 `SOAP-GET` | one-way SOAP 1.1 or 1.2 with HTTP GET
4576 `SOAP1.1-GET` | one-way SOAP 1.1 with HTTP GET
4577 `SOAP1.2-GET` | one-way SOAP 1.2 with HTTP GET
4578 `HTTP` | non-SOAP REST protocol with HTTP POST
4579 `POST` | non-SOAP REST protocol with HTTP POST
4580 `GET` | non-SOAP REST protocol with HTTP GET
4581 `PUT` | non-SOAP REST protocol with HTTP PUT
4582 `DELETE` | non-SOAP REST protocol with HTTP DELETE
4583 
4584 You can bind service operations to the WSDL namespace of a service by using the
4585 namespace prefix as part of the identifier name of the function that defines
4586 the service operation:
4587 
4588 ~~~{.cpp}
4589  int prefix__func(arg1, arg2, ..., argn, result);
4590 ~~~
4591 
4592 You can override the `port` endpoint URL at runtime in the auto-generated
4593 `soap_call_prefix__func` service call (C/C++ client side) and in the C++ proxy
4594 class service call.
4595 
4596 🔝 [Back to table of contents](#)
4597 
4598 Service method directives {#directives-2}
4599 -------------------------
4600 
4601 Service properties are applicable to a service and to all of its operations.
4602 Service method directives are specifically applicable to a service operation.
4603 
4604 A service method directive is of the form:
4605 
4606 ~~~{.cpp}
4607  //gsoap <prefix> service method-<property>: <method> <value>
4608 ~~~
4609 
4610 where `<prefix>` is the XML namespace prefix of a service binding and
4611 `<method>` is the unqualified name of a service operation. The `<property>`
4612 and `<value>` fields are one of the following:
4613 
4614 method property | value
4615 --------------------------- | -----
4616 `method-documentation` | text describing the service operation
4617 `method` | an alias for the `method-documentation` property
4618 `method-action` | `""` or URI SOAPAction HTTP header, or URL query string for REST protocols
4619 `method-input-action` | `""` or URI SOAPAction HTTP header of service request messages
4620 `method-output-action` | `""` or URI SOAPAction HTTP header of service response messages
4621 `method-fault-action` | `""` or URI SOAPAction HTTP header of service fault messages
4622 `method-header-part` | member name of the `SOAP_ENV__Header` struct used in SOAP Header
4623 `method-input-header-part` | member name of the `SOAP_ENV__Header` struct used in SOAP Headers of requests
4624 `method-output-header-part` | member name of the `SOAP_ENV__Header` struct used in SOAP Headers of responses
4625 `method-fault` | type name of a struct or class member used in `SOAP_ENV__Details` struct
4626 `method-mime-type` | REST content type or SOAP MIME attachment content type(s)
4627 `method-input-mime-type` | REST content type or SOAP MIME attachment content type(s) of request message
4628 `method-output-mime-type` | REST content type or SOAP MIME attachment content type(s) of response message
4629 `method-style` | `document` or `rpc`
4630 `method-encoding` | `literal`, `encoded`, or a custom URI for encodingStyle of messages
4631 `method-response-encoding` | `literal`, `encoded`, or a custom URI for encodingStyle of response messages
4632 `method-protocol` | SOAP or REST, see [service directives](#directives-1)
4633 
4634 The `method-header-part` properties can be repeated for a service operation to
4635 declare multiple SOAP Header parts that the service operation requires. You
4636 can use `method-input-header-part` and `method-output-header-part` to
4637 differentiate between request and response messages.
4638 
4639 The `method-fault` property can be repeated for a service operation to declare
4640 multiple faults that the service operation may return.
4641 
4642 The `method-action` property serves two purposes:
4643 
4644 -# To set the SOAPAction header for SOAP protocols, i.e. sets the
4645  definitions/binding/operation/SOAP:operation/\@soapAction.
4646 
4647 -# To set the URL query string for endpoints with REST protocols, i.e. sets the
4648  definitions/binding/operation/HTTP:operation/\@location, which specifies
4649  a URL query string (starts with a `?`) to complete the service endpoint URL
4650  or extends the endpoint URL with a local path (starts with a `/`).
4651 
4652 Use `method-input-action` and `method-output-action` to differentiate the
4653 SOAPAction between SOAP request and response messages.
4654 
4655 You can always override the port endpoint URL and action values at runtime in
4656 the auto-generated `soap_call_prefix__func` service call (C/C++ client side)
4657 and in the auto-generated C++ proxy class service calls. A runtime NULL
4658 endpoint URL and/or action uses the defaults set by these directives.
4659 
4660 The `method-mime-type` property serves two purposes:
4661 
4662 -# To set the type of MIME/MTOM attachments used with SOAP protocols. Multiple
4663  attachment types can be declared for a SOAP service operation, i.e. adds
4664  definitions/binding/operation/input/MIME:multipartRelated/MIME:part/MIME:content/\@type
4665  for each type specified.
4666 
4667 -# To set the MIME type of a REST operation. This replaces XML declared in
4668  WSDL by definitions/binding/operation/(input|output)/MIME:mimeXml with
4669  MIME:content/\@type. Use `application/x-www-form-urlencoded` with REST POST
4670  and PUT protocols to send encoded form data automatically instead of XML.
4671  Only primitive type values can be transmitted with form data, such as
4672  numbers and strings, i.e. only types that are legal to use as
4673  [attributes members](#toxsd9-5).
4674 
4675 Use `method-input-mime-type` and `method-output-mime-type` to differentiate the
4676 attachment types between request and response messages.
4677 
4678 🔝 [Back to table of contents](#)
4679 
4680 Schema directives {#directives-3}
4681 -----------------
4682 
4683 A schema directive is of the form:
4684 
4685 ~~~{.cpp}
4686  //gsoap <prefix> schema <property>: <value>
4687 ~~~
4688 
4689 where `<prefix>` is the XML namespace prefix of a schema. The `<property>` and
4690 `<value>` fields are one of the following:
4691 
4692 property | value
4693 --------------- | -----
4694 `namespace` | URI of the XSD targetNamespace
4695 `namespace2` | alternate URI pattern for the XSD namespace (i.e. URI is also accepted by the XML parser)
4696 `import` | URI of an imported namespace, as an alternative or in addition to `namespace`, adds `xsd:import` to the generated WSDL and XSD files
4697 `form` | `unqualified` (default) or `qualified` local element and attribute form defaults
4698 `elementForm` | `unqualified` (default) or `qualified` local element form default
4699 `attributeForm` | `unqualified` (default) or `qualified` local attribute form default
4700 `typed` | `no` (default) or `yes` for serializers to add `xsi:type` attributes to XML
4701 
4702 To learn more about the local form defaults, see [qualified and unqualified members.](#toxsd9-6)
4703 
4704 The `namespace2` URI is a pattern with `*` matching any sequence of characters
4705 and `-` matching any character. This pattern instructs the XML parser and validator
4706 to also accept the URI pattern as a valid namespace for the specified `<prefix>`.
4707 
4708 The `typed` property is implicitly `yes` when <b>`soapcpp2 -t`</b> option <b>`-t`</b> is used.
4709 
4710 🔝 [Back to table of contents](#)
4711 
4712 Schema type directives {#directives-4}
4713 ----------------------
4714 
4715 A schema type directive is of the form:
4716 
4717 ~~~{.cpp}
4718  //gsoap <prefix> schema type-<property>: <name> <value>
4719  //gsoap <prefix> schema type-<property>: <name>::<member> <value>
4720 ~~~
4721 
4722 where `<prefix>` is the XML namespace prefix of a schema and `<name>` is an
4723 unqualified name of a C/C++ type, and the optional `<member>` is a class/struct
4724 members or enum constant.
4725 
4726 You can describe a type with one of the following:
4727 
4728 type property | value
4729 -------------------- | -----
4730 `type-documentation` | text describing the schema type
4731 `type` | an alias for the `type-documentation` property
4732 
4733 For example, you can add a description to an enumeration:
4734 
4735 ~~~{.cpp}
4736  //gsoap ns schema type: Vowels The letters A, E, I, O, U, and sometimes Y
4737  //gsoap ns schema type: Vowels::Y A vowel, sometimes
4738  enum class ns__Vowels : char { A = 'A', E = 'E', I = 'I', O = 'O', U = 'U', Y = 'Y' };
4739 ~~~
4740 
4741 This documented enumeration maps to a simpleType restriction of <i>`xsd:string`</i> in
4742 the soapcpp2-generated schema:
4743 
4744 <div class="alt">
4745 ~~~{.xml}
4746  <simpleType name="Vowels">
4747  <annotation>
4748  <documentation>The letters A, E, I, O, U, and sometimes Y</documentation>
4749  </annotation>
4750  <restriction base="xsd:string">
4751  <enumeration value="A"/>
4752  <enumeration value="E"/>
4753  <enumeration value="I"/>
4754  <enumeration value="O"/>
4755  <enumeration value="U"/>
4756  <enumeration value="Y">
4757  <annotation>
4758  <documentation>A vowel, sometimes</documentation>
4759  </annotation>
4760  <enumeration/>
4761  </restriction>
4762  </simpleType>
4763 ~~~
4764 </div>
4765 
4766 🔝 [Back to table of contents](#)
4767 
4768 Serialization rules {#rules}
4769 ===================
4770 
4771 A presentation on XML data bindings is not complete without discussing the
4772 serialization rules and options that put your data in XML on the wire or store
4773 it a file or buffer.
4774 
4775 There are several options to choose from to serialize data in XML. The choice
4776 depends on the use of the SOAP protocol or if SOAP is not required. The wsdl2h
4777 tool automates this for you by taking the WSDL transport bindings into account
4778 when generating the service functions in C and C++ that use SOAP or REST.
4779 
4780 The gSOAP tools are not limited to SOAP. The tools implement generic XML data
4781 bindings for SOAP, REST, and other uses of XML. So you can read and write XML
4782 using the serializing [operations on classes and structs](#toxsd9-14).
4783 
4784 The following sections briefly explain the serialization rules with respect to
4785 the SOAP protocol for XML Web services. A basic understanding of the SOAP
4786 protocol is useful when developing client and server applications that must
4787 interoperate with other SOAP applications.
4788 
4789 SOAP/REST Web service client and service operations are represented as
4790 functions in your interface header file with the data binding interface for
4791 soapcpp2. The soapcpp2 tool will translate these function to client-side
4792 service invocation calls and server-side service operation dispatchers.
4793 
4794 A discussion of SOAP clients and servers is beyond the scope of this article.
4795 However, the SOAP options discussed here also apply to SOAP client and server
4796 development.
4797 
4798 🔝 [Back to table of contents](#)
4799 
4800 SOAP document versus rpc style {#doc-rpc}
4801 ------------------------------
4802 
4803 The `wsdl:binding/soap:binding/@style` attribute in the <i>`<wsdl:binding>`</i>
4804 section of a WSDL is either "document" or "rpc". The "rpc" style refers to
4805 SOAP RPC (Remote Procedure Call), which is more restrictive than the "document"
4806 style by requiring one XML element in the SOAP Body to act as the procedure
4807 name with XML subelements as its parameters.
4808 
4809 For example, the following directives in the interface header file for soapcpp2
4810 declare that `DBupdate` is a SOAP RPC encoding service method:
4811 
4812 ~~~{.cpp}
4813  //gsoap ns service namespace: urn:DB
4814  //gsoap ns service method-protocol: DBupdate SOAP
4815  //gsoap ns service method-style: DBupdate rpc
4816  int ns__DBupdate(...);
4817 ~~~
4818 
4819 The XML payload has a SOAP envelope, optional SOAP header, and a SOAP body with
4820 one element representing the operation with the parameters as subelements:
4821 
4822 <div class="alt">
4823 ~~~{.xml}
4824  <SOAP-ENV:Envelope
4825  xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
4826  xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"
4827  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4828  xmlns:xsd="http://www.w3.org/2001/XMLSchema"
4829  xmlsn:ns="urn:DB">
4830  <SOAP-ENV:Body>
4831  <ns:DBupdate>
4832  ...
4833  </ns:DBupdate>
4834  </SOAP-ENV:Body>
4835  </SOAP-ENV:Envelope>
4836 ~~~
4837 </div>
4838 
4839 The "document" style puts no restrictions on the SOAP Body content. However, we
4840 recommend that the first element's tag name in the SOAP Body should be unique
4841 to each type of operation, so that the receiver can dispatch the operation
4842 based on this element's tag name. Alternatively, the HTTP URL path can be used
4843 to specify the operation, or the HTTP action header can be used to dispatch
4844 operations automatically on the server side (soapcpp2 options -a and -A).
4845 
4846 🔝 [Back to table of contents](#)
4847 
4848 SOAP literal versus encoding {#lit-enc}
4849 ----------------------------
4850 
4851 The `wsdl:operation/soap:body/@use` attribute in the <i>`<wsdl:binding>`</i> section
4852 of a WSDL is either "literal" or "encoded". The "encoded" use refers to the
4853 SOAP encoding rules that support id-ref multi-referenced elements to serialize
4854 data as graphs.
4855 
4856 SOAP encoding is very useful if the data internally forms a graph (including
4857 cycles) and we want the graph to be serialized in XML in a format that ensures
4858 that its structure is preserved. In that case, SOAP 1.2 encoding is the best
4859 option.
4860 
4861 SOAP encoding also adds encoding rules for [SOAP arrays](#toxsd10) to serialize
4862 multi-dimensional arrays. The use of XML attributes to exchange XML data in
4863 SOAP encoding is not permitted. The only attributes permitted are the standard
4864 XSD attributes, SOAP encoding attributes (such as for arrays), and id-ref.
4865 
4866 For example, the following directives in the interface header file for soapcpp2
4867 declare that `DBupdate` is a SOAP RPC encoding service method:
4868 
4869 ~~~{.cpp}
4870  //gsoap ns service namespace: urn:DB
4871  //gsoap ns service method-protocol: DBupdate SOAP
4872  //gsoap ns service method-style: DBupdate rpc
4873  //gsoap ns service method-encoding: DBupdate encoded
4874  int ns__DBupdate(...);
4875 ~~~
4876 
4877 The XML payload has a SOAP envelope, optional SOAP header, and a SOAP body with
4878 an encodingStyle attribute for SOAP 1.1 encoding and an element representing the
4879 operation with parameters that are SOAP 1.1 encoded:
4880 
4881 <div class="alt">
4882 ~~~{.xml}
4883  <SOAP-ENV:Envelope
4884  xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
4885  xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"
4886  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4887  xmlns:xsd="http://www.w3.org/2001/XMLSchema"
4888  xmlsn:ns="urn:DB">
4889  <SOAP-ENV:Body SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
4890  <ns:DBupdate>
4891  <records SOAP-ENC:arrayType="ns:record[3]">
4892  <item>
4893  <name href="#_1"/>
4894  <SSN>1234567890</SSN>
4895  </item>
4896  <item>
4897  <name>Jane</name>
4898  <SSN>1987654320</SSN>
4899  </item>
4900  <item>
4901  <name href="#_1"/>
4902  <SSN>2345678901</SSN>
4903  </item>
4904  </records>
4905  </ns:DBupdate>
4906  <id id="_1" xsi:type="xsd:string">Joe</id>
4907  </SOAP-ENV:Body>
4908  </SOAP-ENV:Envelope>
4909 ~~~
4910 </div>
4911 
4912 In the XML fragment shown above the name "Joe" is shared by two records and the
4913 string is referenced by SOAP 1.1 href and id attributes.
4914 
4915 While the soapcpp-generated serializers only introduce multi-referenced
4916 elements in the payload when they are actually multi-referenced in the data
4917 graph, other SOAP applications may render multi-referenced elements more
4918 aggressively. The example could also be rendered as:
4919 
4920 <div class="alt">
4921 ~~~{.xml}
4922  <SOAP-ENV:Envelope
4923  xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
4924  xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"
4925  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4926  xmlns:xsd="http://www.w3.org/2001/XMLSchema"
4927  xmlsn:ns="urn:DB">
4928  <SOAP-ENV:Body SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
4929  <ns:DBupdate>
4930  <records SOAP-ENC:arrayType="ns:record[3]">
4931  <item href="#id1"/>
4932  <item href="#id2"/>
4933  <item href="#id3"/>
4934  </records>
4935  </ns:DBupdate>
4936  <id id="id1" xsi:type="ns:record">
4937  <name href="#id4"/>
4938  <SSN>1234567890</SSN>
4939  </id>
4940  <id id="id2" xsi:type="ns:record">
4941  <name href="#id5"/>
4942  <SSN>1987654320</SSN>
4943  </id>
4944  <id id="id3" xsi:type="ns:record">
4945  <name href="#id4"/>
4946  <SSN>2345678901</SSN>
4947  </id>
4948  <id id="id4" xsi:type="xsd:string">Joe</id>
4949  <id id="id5" xsi:type="xsd:string">Jane</id>
4950  </SOAP-ENV:Body>
4951  </SOAP-ENV:Envelope>
4952 ~~~
4953 </div>
4954 
4955 SOAP 1.2 encoding is cleaner and produces more accurate XML encodings of data
4956 graphs by setting the id attribute on the element that is referenced:
4957 
4958 <div class="alt">
4959 ~~~{.xml}
4960  <SOAP-ENV:Envelope
4961  xmlns:SOAP-ENV="http://www.w3.org/2003/05/soap-envelope"
4962  xmlns:SOAP-ENC="http://www.w3.org/2003/05/soap-encoding"
4963  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4964  xmlns:xsd="http://www.w3.org/2001/XMLSchema"
4965  xmlsn:ns="urn:DB">
4966  <SOAP-ENV:Body>
4967  <ns:DBupdate SOAP-ENV:encodingStyle="http://www.w3.org/2003/05/soap-encoding">
4968  <records SOAP-ENC:itemType="ns:record" SOAP-ENC:arraySize="3">
4969  <item>
4970  <name SOAP-ENC:id="_1">Joe</name>
4971  <SSN>1234567890</SSN>
4972  </item>
4973  <item>
4974  <name>Jane</name>
4975  <SSN>1987654320</SSN>
4976  </item>
4977  <item>
4978  <name SOAP-ENC:ref="_1"/>
4979  <SSN>2345678901</SSN>
4980  </item>
4981  </records>
4982  </ns:DBupdate>
4983  </SOAP-ENV:Body>
4984  </SOAP-ENV:Envelope>
4985 ~~~
4986 </div>
4987 
4988 @note Some SOAP 1.2 applications consider the namespace `SOAP-ENC` of
4989 <i>`SOAP-ENC:id`</i> and <i>`SOAP-ENC:ref`</i> optional. With gSOAP, the SOAP
4990 1.2 encoding serialization follows the 2007 standard, while accepting
4991 unqualified id and ref attributes.
4992 
4993 To remove all rendered id-ref multi-referenced elements, use the
4994 `SOAP_XML_TREE` flag to initialize the `soap` context.
4995 
4996 Some XSD validation rules are turned off with SOAP encoding, because of the
4997 presence of additional attributes, such as id and ref/href, SOAP arrays with
4998 arbitrary element tags for array elements, and the occurrence of additional
4999 multi-ref elements in the SOAP 1.1 Body.
5000 
5001 The use of "literal" puts no restrictions on the XML in the SOAP Body. Full
5002 XSD validation is possible, which can be enabled with the `SOAP_XML_STRICT`
5003 flag to initialize the `soap` context. However, data graphs will be
5004 serialized as trees and cycles in the data will be cut from the XML rendition.
5005 
5006 🔝 [Back to table of contents](#)
5007 
5008 SOAP 1.1 versus SOAP 1.2 {#soap}
5009 ------------------------
5010 
5011 There are two SOAP protocol versions: 1.1 and 1.2. The gSOAP tools can switch
5012 between the two versions seamlessly. You can declare the default SOAP version
5013 for a service operation as follows:
5014 
5015 ~~~{.cpp}
5016  //gsoap ns service method-protocol: DBupdate SOAP1.2
5017 ~~~
5018 
5019 Use `SOAP` (SOAP 1.1), `SOAP1.1`, `SOAP1.2`, and `HTTP` to switch SOAP versions
5020 or enable REST methods with HTTP POST. See [service directives](#directives-1)
5021 and [XML serialization](#non-soap).
5022 
5023 The soapcpp2 tool auto-generates client and server code. At the client side,
5024 this operation sends data with SOAP 1.2 but accepts responses also in SOAP 1.1.
5025 At the server side, this operation accepts requests in SOAP 1.1 and 1.2 and
5026 will return responses in the same SOAP version.
5027 
5028 As we discussed in the previous section, the SOAP 1.2 protocol has a cleaner
5029 multi-referenced element serialization format that greatly enhances the
5030 accuracy of data graph serialization with SOAP RPC encoding and is therefore
5031 recommended.
5032 
5033 The SOAP 1.2 protocol default can also be set by importing and loading
5034 <i>`gsoap/import/soap12.h`</i>:
5035 
5036 ~~~{.cpp}
5037  #import "soap12.h"
5038 ~~~
5039 
5040 Finally, the soapcpp2 tool has options to force SOAP 1.1, SOAP 1.2, or remove
5041 SOAP altogether with <b>`soapcpp2 -1`</b> (SOAP 1.1), <b>`soapcpp2 -2`</b>
5042 (SOAP 1.2) and <b>`soapcpp2 -0`</b> (plain XML, no SOAP).
5043 
5044 🔝 [Back to table of contents](#)
5045 
5046 XML serialization {#non-soap}
5047 -----------------
5048 
5049 You can serialize data to XML that is stored on the heap, on the stack (locals), and
5050 static data as long as the serializable (i.e. non-transient) values are
5051 properly initialized and pointers in the data structures are either NULL or
5052 point to valid structures.
5053 
5054 When XML is deserialized into data, the data is put on the heap and managed by the
5055 `::soap` context, see also [memory management](#memory).
5056 
5057 You can read and write XML directly to a file or stream with the serializing
5058 [operations on classes and structs](#toxsd9-14).
5059 
5060 To define and use XML Web service client and service operations, we can declare
5061 these operations in your interface header file with the data binding interface
5062 for soapcpp2 as functions. The function are translated by soapcpp2 to
5063 client-side service invocation calls and server-side service operation
5064 dispatchers.
5065 
5066 The REST operations POST, GET, and PUT are declared with `//gsoap` directives
5067 in the interface header file for soapcpp2. For example, a REST HTTP POST
5068 operation is declared as follows:
5069 
5070 ~~~{.cpp}
5071  //gsoap ns service namespace: urn:DB
5072  //gsoap ns service method-protocol: DBupdate POST
5073  int ns__DBupdate(...);
5074 ~~~
5075 
5076 There are no SOAP Envelope and SOAP Body elements in the payload for
5077 `DBupdate`. Also the XML serialization rules are identical to SOAP
5078 document/literal, meaning no SOAP RPC encoding XML structures are implicitly
5079 used. The XML payload only has the operation name as an element with its
5080 parameters serialized as subelements:
5081 
5082 <div class="alt">
5083 ~~~{.xml}
5084  <ns:DBupdate xmln:ns="urn:DB" ...>
5085  ...
5086  </ns:DBupdate>
5087 ~~~
5088 </div>
5089 
5090 To force id-ref serialization with REST similar to SOAP 1.2 multi-reference
5091 encoding, use the `SOAP_XML_GRAPH` flag to initialize the `soap` context.
5092 The XML serialization includes id and ref attributes for multi-referenced
5093 elements as follows:
5094 
5095 <div class="alt">
5096 ~~~{.xml}
5097  <ns:DBupdate xmln:ns="urn:DB" ...>
5098  <records>
5099  <item>
5100  <name id="_1">Joe</name>
5101  <SSN>1234567890</SSN>
5102  </item>
5103  <item>
5104  <name>Jane</name>
5105  <SSN>1987654320</SSN>
5106  </item>
5107  <item>
5108  <name ref="_1"/>
5109  <SSN>2345678901</SSN>
5110  </item>
5111  </records>
5112  </ns:DBupdate>
5113 ~~~
5114 </div>
5115 
5116 🔝 [Back to table of contents](#)
5117 
5118 Input and output {#io}
5119 ================
5120 
5121 Reading and writing XML from/to files, streams and string buffers is done via
5122 the managing `soap` context by setting one of the following context variables that
5123 control IO sources and sinks:
5124 
5125 ~~~{.cpp}
5126  soap->recvfd = fd; // an int file descriptor to read from (0 by default)
5127  soap->sendfd = fd; // an int file descriptor to write to (1 by default)
5128  soap->is = &is; // C++ only: a std::istream is object to read from
5129  soap->os = &os; // C++ only: a std::ostream os object to write to
5130  soap->is = cs; // C only: a const char* string to read from (soap->is will advance)
5131  soap->os = &cs; // C only: pointer to a const char*, will be set to point to the string output
5132 ~~~
5133 
5134 Normally, all of these context variables are NULL, which is required to send and
5135 receive data over sockets by gSOAP client and server applications. Therefore,
5136 if you set any of these context variables in a client or server application
5137 then you should reset them to NULL to ensure that socket communications are not
5138 blocked.
5139 
5140 @note The use of `soap::is` and `soap::os` in C requires gSOAP 2.8.28 or greater.
5141 
5142 In the following sections, we present more details on how to read and write to
5143 files and streams, and use string buffers as sources and sinks for XML data.
5144 
5145 In addition, you can set IO callback functions to handle IO at a lower level.
5146 For more details on defining your own callback functions, see the
5147 [gSOAP user guide.](../../guide/html/index.html)
5148 
5149 🔝 [Back to table of contents](#)
5150 
5151 Reading and writing from/to files and streams {#io1}
5152 ---------------------------------------------
5153 
5154 The default IO is standard input and output. Other sources and sinks (those
5155 listed above) will be used until you (re)set them. For example with file-based
5156 input and output:
5157 
5158 ~~~{.cpp}
5159  FILE *fp = fopen("record.xml", "r");
5160  if (fp != NULL)
5161  {
5162  soap->recvfd = fileno(fp); // get file descriptor of file to read from
5163  if (soap_read_ns__record(soap, &pers1))
5164  ... // handle IO error
5165  fclose(fp);
5166  soap->recvfd = 0; // read from stdin, or -1 to block reading
5167  }
5168 
5169  FILE *fp = fopen("record.xml", "w");
5170  if (fp != NULL)
5171  {
5172  soap->sendfd = fileno(fp); // get file descriptor of file to write to
5173  if (soap_write_ns__record(soap, &pers1))
5174  ... // handle IO error
5175  fclose(fp);
5176  soap->sendfd = 1; // write to stdout, or -1 to block writing
5177  }
5178 ~~~
5179 
5180 Similar code with streams in C++:
5181 
5182 ~~~{.cpp}
5183  #include <fstream>
5184 
5185  std::fstream fs;
5186  fs.open("record.xml", std::ios::in);
5187  if (fs)
5188  {
5189  soap->is = &fs;
5190  if (soap_read__ns__record(soap, &pers1))
5191  ... // handle IO error
5192  fs.close();
5193  soap->is = NULL;
5194  }
5195 
5196  fs.open("record.xml", std::ios::out);
5197  if (fs)
5198  {
5199  soap->os = &fs;
5200  if (soap_write__ns__record(soap, &pers1))
5201  ... // handle IO error
5202  fs.close();
5203  soap->os = NULL;
5204  }
5205 ~~~
5206 
5207 🔝 [Back to table of contents](#)
5208 
5209 Reading and writing from/to string buffers {#io2}
5210 ------------------------------------------
5211 
5212 For C++ we recommend to use `std::stringstream` objects from the
5213 <i>`sstream`</i> C++ library as illustrated in the following example:
5214 
5215 ~~~{.cpp}
5216  #include <sstream>
5217 
5218  std::stringstream ss;
5219  ss.str("..."); // XML to parse
5220  soap->is = &ss;
5221  if (soap_read__ns__record(soap, &pers1))
5222  ... // handle IO error
5223  soap->is = NULL;
5224 
5225  soap->os = &ss;
5226  if (soap_write__ns__record(soap, &pers1))
5227  ... // handle IO error
5228  soap->os = NULL;
5229  std::string s = ss.str(); // string with XML
5230 ~~~
5231 
5232 For C we can use `soap::is` and `soap::os` to point to strings of XML content
5233 as follows (this requires gSOAP 2.8.28 or later):
5234 
5235 ~~~{.cpp}
5236  soap->is = "..."; // XML to parse
5237  if (soap_read__ns__record(soap, &pers1))
5238  ... // handle IO error
5239  soap->is = NULL;
5240 
5241  const char *cs = NULL;
5242  soap->os = &cs;
5243  if (soap_write__ns__record(soap, &pers1))
5244  ... // handle IO error
5245  soap->os = NULL;
5246  ... = cs; // string with XML (do not free(cs): managed by the context and freed with soap_end())
5247 ~~~
5248 
5249 The type of `soap::os` is a pointer to a `const char*` string. The pointer is
5250 set by the managing `soap` context to point to the XML data that is stored on
5251 the context-managed heap.
5252 
5253 For earlier gSOAP versions we recommend to use IO callbacks `soap::frecv` and
5254 `soap::fsend`, see the [gSOAP user guide.](../../guide/html/index.html).
5255 
5256 🔝 [Back to table of contents](#)
5257 
5258 Memory management {#memory}
5259 =================
5260 
5261 Memory management with the `soap` context enables us to allocate data in
5262 context-managed heap space that can be collectively deleted. All deserialized
5263 data is placed on the context-managed heap by the `soap` context of the engine.
5264 
5265 🔝 [Back to table of contents](#)
5266 
5267 Memory management in C {#memory1}
5268 ----------------------
5269 
5270 When working with gSOAP in C (i.e. using <b>`wsdl2h -c`</b> option <b>`-c`</b>
5271 or <b>`soapcpp2 -c`</b> option <b>`-c`</b>), data is allocated on the managed heap with:
5272 
5273 - `void *soap_malloc(struct soap*, size_t len)`.
5274 
5275 This function allocates `len` bytes on the heap managed by the specified
5276 context and returns NULL when allocation failed.
5277 
5278 You can also make shallow copies of data with `soap_memdup` that uses
5279 `soap_malloc` and a safe version of `memcpy` to copy a chunk of data `src` with
5280 length `len` to the context-managed heap:
5281 
5282 - `void * soap_memdup(struct soap*, const void *src, size_t len)`
5283 
5284 This function returns a pointer to the copy. This function requires gSOAP
5285 2.8.27 or later.
5286 
5287 In gSOAP 2.8.35 and greater versions, you can use an auto-generated function to
5288 allocate and initialize data of type `T` on the managed heap:
5289 
5290 - `T * soap_new_T(struct soap*, int n)`
5291 
5292 This function returns an array of length `n` of type `T` data that is default
5293 initialized (by internally calling `soap_malloc(soap, n * sizeof(T))` and then
5294 `soap_default_T(soap, T*)` on each array value). Use a negative value or `n=1`
5295 to allocate and initialize a single value. This function returns NULL when
5296 allocation failed.
5297 
5298 The `soap_malloc` function is essentially a wrapper around `malloc`, but
5299 permits the `soap` context to track all heap allocations for collective
5300 deletion with `soap_end(soap)`:
5301 
5302 ~~~{.cpp}
5303  #include "soapH.h"
5304  #include "ns.nsmap"
5305  ...
5306  struct soap *soap = soap_new(); // new context
5307  ...
5308  struct ns__record *record = (struct ns__record*)soap_malloc(soap, sizeof(struct ns__record));
5309  soap_default_ns__record(soap, record); // auto-generated struct initializer
5310  ...
5311  soap_destroy(soap); // only for C++, see section on C++ below
5312  soap_end(soap); // delete record and all other heap allocations
5313  soap_free(soap); // delete context
5314 ~~~
5315 
5316 All data on the managed heap is mass-deleted with `soap_end(soap)` which must
5317 be called before `soap_done(soap)` or `soap_free(soap)`, which end the use of
5318 the `soap` context and free the context, respectively. Use
5319 `soap_free(soap)` only when the context is allocated with `soap_new()`. Use
5320 `soap_done(soap)` only when the context is stack allocated (so cannot be
5321 deleted from the heap).
5322 
5323 The managed heap is checked for memory leaks at run time when the source code
5324 is compiled with option <b>`-DDEBUG`</b>.
5325 
5326 The soapcpp2 auto-generated deserializers in C use `soap_malloc` to allocate
5327 and populate deserialized structures, which are managed by the context for
5328 collective deletion.
5329 
5330 To make `char*` and `wchar_t*` string copies to the context-managed heap, we
5331 can use the functions:
5332 
5333 - `char *soap_strdup(struct soap*, const char *str)` and
5334 
5335 - `wchar_t *soap_wstrdup(struct soap*, const wchar_t *wstr)`.
5336 
5337 If your C compiler supports `typeof` then you can use the following macro to
5338 simplify the managed heap allocation and initialization of primitive values:
5339 
5340 ~~~{.cpp}
5341  #define soap_assign(soap, lhs, rhs) (*(lhs = (typeof(lhs))soap_malloc(soap, sizeof(*lhs))) = rhs)
5342 ~~~
5343 
5344 Pointers to primitive values are often used for optional members. For example,
5345 assume we have the following struct:
5346 
5347 ~~~{.cpp}
5348  struct ns__record
5349  {
5350  const char *name 1; // required (minOccurs=1)
5351  uint64_t *SSN; // optional (pointer means minOccurs=0)
5352  struct ns__record *spouse; // optional (pointer means minOccurs=0)
5353  };
5354 ~~~
5355 
5356 Use `soap_assign` to create a SSN value on the managed heap:
5357 
5358 ~~~{.cpp}
5359  struct soap *soap = soap_new(); // new context
5360  ...
5361  struct ns__record *record = (struct ns__record*)soap_malloc(soap, sizeof(struct ns__record));
5362  soap_default_ns__record(soap, record);
5363  record->name = soap_strdup(soap, "Joe");
5364  soap_assign(soap, record->SSN, 1234567890UL);
5365  ...
5366  soap_end(soap); // delete managed soap_malloc'ed heap data
5367  soap_free(soap); // delete context
5368 ~~~
5369 
5370 Without the `soap_assign` macro, you will need two lines of code, one to
5371 allocate and one to assign (you should also use this if your system can run out
5372 of memory):
5373 
5374 ~~~{.cpp}
5375  assert((record->SSN = (uint64_t*)soap_malloc(soap, sizeof(utint64_t))) != NULL);
5376  *record->SSN = 1234567890UL;
5377 ~~~
5378 
5379 The serializer can serialize any heap, stack, or static allocated data. So we
5380 can also create a new record as follows:
5381 
5382 ~~~{.cpp}
5383  struct soap *soap = soap_new(); // new context
5384  ...
5385  struct ns__record *record = (struct ns__record*)soap_malloc(soap, sizeof(struct ns__record));
5386  static uint64_t SSN = 1234567890UL;
5387  soap_default_ns__record(soap, record);
5388  record->name = "Joe";
5389  record->SSN = &SSN; // safe to use static values: the value of record->SSN is never changed
5390  ...
5391  soap_end(soap); // delete managed soap_malloc'ed heap data
5392  soap_free(soap); // delete context
5393 ~~~
5394 
5395 Use the soapcpp2 auto-generated `soap_dup_T` functions to duplicate data into
5396 another `soap` context (this requires <b>`soapcpp2 -Ec`</b> option <b>`-Ec`</b> to
5397 generate), here shown for C with the second argument `dst` NULL because we want
5398 to allocate a new managed structure:
5399 
5400 ~~~{.cpp}
5401  struct soap *other_soap = soap_new(); // another context
5402  struct ns__record *other_record = soap_dup_ns__record(other_soap, NULL, record);
5403  ...
5404  soap_destroy(other_soap); // only for C++, see section on C++ below
5405  soap_end(other_soap); // delete other_record and all of its deep data
5406  soap_free(other_soap); // delete context
5407 ~~~
5408 
5409 The only reason to use another `soap` context and not to use the primary `soap`
5410 context is when the primary context must be destroyed together with all of the
5411 objects it manages while some of the objects must be kept alive. If the
5412 objects that are kept alive contain deep cycles then this is the only option we
5413 have, because deep copy with a managing `soap` context detects and preserves
5414 these cycles unless the `SOAP_XML_TREE` flag is used with the `soap` context:
5415 
5416 ~~~{.cpp}
5417  struct soap *other_soap = soap_new1(SOAP_XML_TREE); // another context
5418  struct ns__record *other_record = soap_dup_ns__record(other_soap, NULL, record);
5419 ~~~
5420 
5421 The resulting deep copy will be a full copy of the source data structure as a
5422 tree without co-referenced data (i.e. no digraph) and without cycles. Cycles
5423 are pruned and (one of the) pointers that forms a cycle is repaced by NULL.
5424 
5425 You can also deep copy into unmanaged space and use the auto-generated
5426 `soap_del_T()` function (requires <b>`soapcpp2 -Ed`</b> option <b>`-Ed`</b> to generate) to delete
5427 it later:
5428 
5429 ~~~{.cpp}
5430  struct ns__record *other_record = soap_dup_ns__record(NULL, NULL, record);
5431  ...
5432  soap_del_ns__record(other_record); // deep delete record data members
5433  free(other_record); // delete the record
5434 ~~~
5435 
5436 But you should not do this for any data that has deep cycles in its runtime
5437 data structure. Cycles in the data structure will lead to non-termination when
5438 making unmanaged deep copies. Consider for example:
5439 
5440 ~~~{.cpp}
5441  struct ns__record
5442  {
5443  const char *name 1; // required (minOccurs=1)
5444  uint64_t SSN; // required (non-pointer means minOccurs=1)
5445  struct ns__record *spouse; // optional (pointer means minOccurs=0)
5446  };
5447 ~~~
5448 
5449 The code to populate a structure with a mutual spouse relationship:
5450 
5451 ~~~{.cpp}
5452  struct soap *soap = soap_new();
5453  ...
5454  struct ns__record pers1, pers2;
5455  soap_default_ns__record(soap, &pers1);
5456  soap_default_ns__record(soap, &pers2);
5457  pers1.name = "Joe"; // OK to serialize static data
5458  pers1.SSN = 1234567890;
5459  pers1.spouse = &pers2;
5460  pers2.name = soap_strdup(soap, "Jane"); // allocates and copies a string
5461  pers2.SSN = 1987654320;
5462  pers2.spouse = &pers1;
5463  ...
5464  struct ns__record *pers3 = soap_dup_ns__record(NULL, NULL, &pers1); // BAD
5465  struct ns__record *pers4 = soap_dup_ns__record(soap, NULL, &pers1); // OK
5466  soap_set_mode(soap, SOAP_XML_TREE);
5467  struct ns__record *pers5 = soap_dup_ns__record(soap, NULL, &pers1); // OK
5468 ~~~
5469 
5470 The bad case is where there is no context used in the first argument. The deep
5471 copy functions use a context to keep track of co-referenced data nodes and
5472 cycles in the data structure copies, to copy co-referenced nodes just once.
5473 Co-references in a data structure are formed by pointers and smart pointers
5474 such as `std::shared_ptr`, such that at least two pointers point to the same
5475 data.
5476 
5477 The serializer can serialize any heap, stack, or static allocated data, such as
5478 in the code shown above. So we can serialize the stack-allocated `pers1`
5479 record as follows:
5480 
5481 ~~~{.cpp}
5482  FILE *fp = fopen("record.xml", "w");
5483  if (fp != NULL)
5484  {
5485  soap->sendfd = fileno(fp); // file descriptor to write to
5486  soap_set_mode(soap, SOAP_XML_GRAPH); // support id-ref w/o requiring SOAP
5487  soap_clr_mode(soap, SOAP_XML_TREE); // if set, clear
5488  soap_write_ns__record(soap, &pers1);
5489  fclose(fp);
5490  soap->sendfd = -1; // block further writing
5491  }
5492 ~~~
5493 
5494 which produces an XML document record.xml that is similar to:
5495 
5496 <div class="alt">
5497 ~~~{.xml}
5498  <ns:record xmlns:ns="urn:types" id="Joe">
5499  <name>Joe</name>
5500  <SSN>1234567890</SSN>
5501  <spouse id="Jane">
5502  <name>Jane</name>
5503  <SSN>1987654320</SSN>
5504  <spouse ref="#Joe"/>
5505  </spouse>
5506  </ns:record>
5507 ~~~
5508 </div>
5509 
5510 Deserialization of an XML document with a SOAP 1.1/1.2 encoded id-ref graph
5511 leads to the same non-termination problem when we later try to copy the data
5512 into unmanaged memory heap space:
5513 
5514 ~~~{.cpp}
5515  struct soap *soap = soap_new1(SOAP_XML_GRAPH); // support id-ref w/o SOAP
5516  ...
5517  struct ns__record pers1;
5518  FILE *fp = fopen("record.xml", "r");
5519  if (fp != NULL)
5520  {
5521  soap->recvfd = fileno(fp);
5522  if (soap_read_ns__record(soap, &pers1))
5523  ... // handle IO error
5524  fclose(fp);
5525  soap->recvfd = -1; // blocks further reading
5526  }
5527  ...
5528  struct ns__record *pers3 = soap_dup_ns__record(NULL, NULL, &pers1); // BAD
5529  struct ns__record *pers4 = soap_dup_ns__record(soap, NULL, &pers1); // OK
5530  soap_set_mode(soap, SOAP_XML_TREE);
5531  struct ns__record *pers5 = soap_dup_ns__record(soap, NULL, &pers1); // OK
5532 ~~~
5533 
5534 Copying data with `soap_dup_T(soap)` into managed heap memory space is always
5535 safe. Copying into unmanaged heap memory space requires diligence. But
5536 deleting unmanaged data is easy with `soap_del_T()`.
5537 
5538 You can also use `soap_del_T()` to delete structures that you created in C, but
5539 only if these structures are created with `malloc` and do NOT contain pointers
5540 to stack and static data.
5541 
5542 You can unlink one or more allocated objects from the managed heap to allow the
5543 object to live after `soap_end(soap)` by using:
5544 
5545 - `void soap_unlink(struct soap *soap, void *ptr)`
5546 
5547 The unlinked heap-allocated data pointed to by `ptr` can be accessed after
5548 `soap_end(soap)`. Do not forget to free the data with `free(ptr)`. Be aware
5549 that `soap_unlink(soap, ptr)` does not perform a deep unlinkage. If `ptr` is a
5550 struct, pointer members will become invalid when pointing to objects on the
5551 managed heap. Use `soap_unlink(soap, ptr->member)` to unlink `member` as well.
5552 
5553 Finally, when data is allocated in managed memory heap space, either explicitly
5554 with the allocation functions shown above or by the soapcpp2-generated
5555 deserializers, you can delegate the management and deletion of this data to
5556 another `soap` context. That context will be responsible to delete the data
5557 with `soap_end(soap)` later:
5558 
5559 - `void delegate_deletion(struct soap *soap_from, struct soap *soap_to)`
5560 
5561 This allows the `soap_from` context to be deleted with `soap_free(soap_from)`
5562 (assuming it is allocated with `soap_new()`, use `soap_done(soap_from)` when
5563 `soap_from` is stack-allocated) while the managed data remains intact. You
5564 can use this function any time, to delegate management and deletion to another
5565 context `soap_to` and then continue with the current context. You can also use
5566 different source `soap_from` contexts to delegate management and deletion to
5567 the other `soap_to` context. To mass delete all managed data, use
5568 `soap_end(soap_to)`.
5569 
5570 🔝 [Back to table of contents](#)
5571 
5572 Memory management in C++ {#memory2}
5573 ------------------------
5574 
5575 When working with gSOAP in C++, the engine allocates data on a managed heap
5576 using `soap_new_T(soap)` to allocate a type with type name `T`. Managed heap
5577 allocation is tracked by the `soap` context for collective deletion with
5578 `soap_destroy(soap)` for structs, classes, and templates and with
5579 `soap_end(soap)` for everything else.
5580 
5581 You should only use `soap_malloc(struct soap*, size_t len)` to allocate
5582 primitive types because constructors are not invoked. Therefore, `soap_new_T`
5583 is preferred. The auto-generated `T * soap_new_T(struct soap*)` returns data
5584 allocated on the managed heap for type `T`. The data is mass-deleted with
5585 `soap_destroy(soap)` followed by `soap_end(soap)`.
5586 
5587 The `soap_new_T` functions return NULL when allocation fails. C++ exceptions
5588 are never raised by the engine and serializers when data is allocated.
5589 
5590 There are four variations of `soap_new_T` functions to allocate data of type
5591 `T` that soapcpp2 auto-generates:
5592 
5593 - `T * soap_new_T(struct soap*)` returns a new instance of `T` that is default
5594  initialized. For classes, initialization is internally performed using the
5595  soapcpp2 auto-generated `void T::soap_default(struct soap*)` method of the
5596  class, but ONLY IF the soapcpp2 auto-generated default constructor is used
5597  that invokes `soap_default()` and was not replaced by a user-defined default
5598  constructor.
5599 
5600 - `T * soap_new_T(struct soap*, int n)` returns an array of `n` new instances of
5601  `T`. The instances in the array are default initialized as described above.
5602 
5603 - `T * soap_new_req_T(struct soap*, ...)` (structs and classes only) returns a
5604  new instance of `T` and sets the required data members to the values
5605  specified in `...`. The required data members are those with nonzero
5606  minOccurs, see the subsections on
5607  [(smart) pointer members and their occurrence constraints](#toxsd9-8) and
5608  [container and array members and their occurrence constraints](#toxsd9-9).
5609 
5610 - `T * soap_new_set_T(struct soap*, ...)` (structs and classes only) returns a
5611  new instance of `T` and sets the public/serializable data members to the values
5612  specified in `...`.
5613 
5614 The above functions can be invoked with a NULL `soap` context, but you are then
5615 responsible to use `delete T` to remove this instance from the unmanaged heap.
5616 
5617 For example, to allocate a managed `std::string` you can use:
5618 
5619 ~~~{.cpp}
5620  std::string *s = soap_new_std__string(soap);
5621 ~~~
5622 
5623 To throw a `std::bad_alloc` exception when memory allocation fails, we can define the
5624 following class and macro:
5625 
5626 ~~~{.cpp}
5627  class alloc_check {
5628  public:
5629  template<typename T>
5630  T operator=(T ptr)
5631  {
5632  if (ptr == NULL)
5633  throw std::bad_alloc();
5634  return ptr;
5635  }
5636  };
5637 
5638  #define CHECK alloc_check() =
5639 ~~~
5640 
5641 And use `CHECK` as follows to throw an exception when memory allocation fails:
5642 
5643 ~~~{.cpp}
5644  std::string *s = CHECK soap_new_std__string(soap);
5645 ~~~
5646 
5647 To throw a `std::runtime_exception` when memory allocation fails, with file
5648 and line number information where the error occurred, we can define the
5649 following revised version of our exception-throwing macro:
5650 
5651 ~~~{.cpp}
5652  class alloc_failure : public std::runtime_error {
5653  public:
5654  alloc_failure(const char *file, size_t line) : std::runtime_error(error(file, line))
5655  { }
5656  private:
5657  std::string error(const char *file, size_t line) const
5658  {
5659  std::stringstream ss;
5660  ss << "Memory allocation failed in " << file << " at line " << line;
5661  return ss.str();
5662  }
5663  };
5664 
5665  class alloc_check_with_info {
5666  public:
5667  alloc_check_with_info(const char *file, size_t line) : file(file), line(line)
5668  { }
5669  template<typename T>
5670  T operator=(T ptr) const
5671  {
5672  if (ptr == NULL)
5673  throw alloc_failure(file, line);
5674  return ptr;
5675  }
5676  const char *file;
5677  size_t line;
5678  };
5679 
5680  #define CHECK alloc_check_with_info(__FILE__, __LINE__) =
5681 ~~~
5682 
5683 And use `CHECK` as follows to throw an exception with the file and line number
5684 of the location where memory allocation failed:
5685 
5686 ~~~{.cpp}
5687  std::string *s = CHECK soap_new_std__string(soap);
5688 ~~~
5689 
5690 Primitive types and arrays of primitive values may be allocated with
5691 `soap_malloc` (actually, `soap_new_T` calls `soap_malloc` for primitive type
5692 `T`). All primitive types (i.e. no classes, structs, class templates,
5693 containers, and smart pointers) are allocated with `soap_malloc` for reasons of
5694 efficiency.
5695 
5696 You can use a C++ template to simplify the managed allocation and initialization
5697 of primitive values as follows (this is for primitive types only):
5698 
5699 ~~~{.cpp}
5700  template<class T>
5701  T * soap_make(struct soap *soap, T val)
5702  {
5703  T *p = (T*)soap_malloc(soap, sizeof(T));
5704  if (p == NULL)
5705  throw std::bad_alloc();
5706  *p = val;
5707  return p;
5708  }
5709 ~~~
5710 
5711 For example, assuming we have the following class:
5712 
5713 ~~~{.cpp}
5714  class ns__record
5715  {
5716  public:
5717  std::string name; // required (non-pointer means minOccurs=1)
5718  uint64_t *SSN; // optional (pointer means minOccurs=0)
5719  ns__record *spouse; // optional (pointer means minOccurs=0)
5720  };
5721 ~~~
5722 
5723 You can instantiate a record by using the auto-generated
5724 `soap_new_set_ns__record` and use `soap_make` to create a SSN value on the
5725 managed heap as follows:
5726 
5727 ~~~{.cpp}
5728  soap *soap = soap_new(); // new context
5729  ...
5730  ns__record *record = soap_new_set_ns__record(
5731  soap,
5732  "Joe",
5733  soap_make<uint64_t>(soap, 1234567890UL),
5734  NULL);
5735  ...
5736  soap_destroy(soap); // delete record and all other managed instances
5737  soap_end(soap); // delete managed soap_malloc'ed heap data
5738  soap_free(soap); // delete context
5739 ~~~
5740 
5741 All data on the managed heap is mass-deleted with `soap_end(soap)` which must
5742 be called before `soap_done(soap)` or `soap_free(soap)`, which end the use of
5743 the `soap` context and free the context, respectively. Use
5744 `soap_free(soap)` only when the context is allocated with `soap_new()`. Use
5745 `soap_done(soap)` only when the context is stack allocated (so cannot be
5746 deleted from the heap).
5747 
5748 The managed heap is checked for memory leaks at run time when the source code
5749 is compiled with option <b>`-DDEBUG`</b>.
5750 
5751 However, the serializer can serialize any heap, stack, or static allocated
5752 data. So we can also create a new record as follows:
5753 
5754 ~~~{.cpp}
5755  uint64_t SSN = 1234567890UL;
5756  ns__record *record = soap_new_set_ns__record(soap, "Joe", &SSN, NULL);
5757 ~~~
5758 
5759 which will be fine to serialize this record as long as the local `SSN`
5760 stack-allocated value remains in scope when invoking the serializer and/or
5761 using `record`. It does not matter if `soap_destroy` and `soap_end` are called
5762 beyond the scope of `SSN`.
5763 
5764 To facilitate class methods to access the managing context, we can add a soap
5765 context pointer to a class/struct:
5766 
5767 ~~~{.cpp}
5768  class ns__record
5769  {
5770  public:
5771  ...
5772  void create_more(); // needs a context to create more internal data
5773  protected:
5774  struct soap *soap; // the context that manages this instance, or NULL
5775  };
5776 ~~~
5777 
5778 The `soap` context pointer member of the class is set when invoking
5779 `soap_new_T` (and similar) with a non-NULL context argument that will be
5780 assigned to the `soap` member of the class.
5781 
5782 You can also use a template when an array of pointers to values is required.
5783 To create an array of pointers to values, define the following template:
5784 
5785 ~~~{.cpp}
5786  template<class T>
5787  T **soap_make_array(struct soap *soap, T* array, int n) throw (std::bad_alloc)
5788  {
5789  T **p = (T**)soap_malloc(soap, n * sizeof(T*));
5790  if (p == NULL)
5791  throw std::bad_alloc();
5792  for (int i = 0; i < n; ++i)
5793  p[i] = &array[i];
5794  return p;
5795  }
5796 ~~~
5797 
5798 The `array` parameter is a pointer to an array of `n` values. The template
5799 returns an array of `n` pointers that point to the values in that array:
5800 
5801 ~~~{.cpp}
5802  // create an array of 100 pointers to 100 records
5803  int n = 100;
5804  ns__record **precords = soap_make_array(soap, soap_new_ns__record(soap, n), n);
5805  for (int i = 0; i < n; ++i)
5806  {
5807  precords[i]->name = "...";
5808  precords[i]->SSN = soap_make<uint64_t>(1234567890UL + i);
5809  }
5810 ~~~
5811 
5812 Note that `soap_new_ns__record(soap, n)` returns a pointer to an array of `n`
5813 records, which is then used to create an array of `n` pointers to these records.
5814 
5815 Use the soapcpp2 auto-generated `soap_dup_T` functions to duplicate data into
5816 another `soap` context (this requires <b>`soapcpp2 -Ec`</b> option <b>`-Ec`</b> to generate), here shown
5817 for C++ with the second argument `dst` NULL to allocate a new managed object:
5818 
5819 ~~~{.cpp}
5820  soap *other_soap = soap_new(); // another context
5821  ns__record *other_record = soap_dup_ns__record(other_soap, NULL, record);
5822  ...
5823  soap_destroy(other_soap); // delete record and other managed instances
5824  soap_end(other_soap); // delete other data (the SSNs on the heap)
5825  soap_free(other_soap); // delete context
5826 ~~~
5827 
5828 To duplicate base and derived instances when a base class pointer or reference
5829 is provided, use the auto-generated method `T * T::soap_dup(struct soap*)`:
5830 
5831 ~~~{.cpp}
5832  soap *other_soap = soap_new(); // another context
5833  ns__record *other_record = record->soap_dup(other_soap);
5834  ...
5835  soap_destroy(other_soap); // delete record and other managed instances
5836  soap_end(other_soap); // delete other data (the SSNs on the heap)
5837  soap_free(other_soap); // delete context
5838 ~~~
5839 
5840 The only reason to use another context and not to use the primary `soap`
5841 context is when the primary context must be destroyed together with all of the
5842 objects it manages while some of the objects must be kept alive. If the
5843 objects that are kept alive contain deep cycles then this is the only option we
5844 have, because deep copy with a managing `soap` context detects and preserves
5845 these cycles unless the `SOAP_XML_TREE` flag is used with the context:
5846 
5847 ~~~{.cpp}
5848  soap *other_soap = soap_new1(SOAP_XML_TREE); // another context
5849  ns__record *other_record = record->soap_dup(other_soap); // deep tree copy
5850 ~~~
5851 
5852 The resulting deep copy will be a full copy of the source data structure as a
5853 tree without co-referenced data (i.e. no digraph) and without cycles. Cycles
5854 are pruned and (one of the) pointers that forms a cycle is repaced by NULL.
5855 
5856 You can also deep copy into unmanaged space and use the auto-generated
5857 `soap_del_T()` function or the `T::soap_del()` method (requires
5858 <b>`soapcpp2 -Ec`</b> option <b>`-Ec`</b> to generate) to delete it later,
5859 but we should not do this for any data that has deep cycles in its runtime data
5860 structure graph:
5861 
5862 ~~~{.cpp}
5863  ns__record *other_record = record->soap_dup(NULL);
5864  ...
5865  other_record->soap_del(); // deep delete record data members
5866  delete other_record; // delete the record
5867 ~~~
5868 
5869 Cycles in the data structure will lead to non-termination when making unmanaged
5870 deep copies. Consider for example:
5871 
5872 ~~~{.cpp}
5873  class ns__record
5874  {
5875  public:
5876  const char *name 1; // required (minOccurs=1)
5877  uint64_t SSN; // required (non-pointer means minOccurs=1)
5878  ns__record *spouse; // optional (pointer means minOccurs=1)
5879  };
5880 ~~~
5881 
5882 The code to populate a structure with a mutual spouse relationship:
5883 
5884 ~~~{.cpp}
5885  soap *soap = soap_new();
5886  ...
5887  ns__record pers1, pers2;
5888  pers1.name = "Joe";
5889  pers1.SSN = 1234567890;
5890  pers1.spouse = &pers2;
5891  pers2.name = "Jane";
5892  pers2.SSN = 1987654320;
5893  pers2.spouse = &pers1;
5894  ...
5895  ns__record *pers3 = soap_dup_ns__record(NULL, NULL, &pers1); // BAD
5896  ns__record *pers4 = soap_dup_ns__record(soap, NULL, &pers1); // OK
5897  soap_set_mode(soap, SOAP_XML_TREE);
5898  ns__record *pers5 = soap_dup_ns__record(soap, NULL, &pers1); // OK
5899 ~~~
5900 
5901 The serializer can serialize any heap, stack, or static allocated data, such as
5902 shown in the code shown above. So we can serialize the stack-allocated `pers1`
5903 record as follows:
5904 
5905 ~~~{.cpp}
5906  FILE *fp = fopen("record.xml", "w");
5907  if (fp != NULL)
5908  {
5909  soap->sendfd = fileno(fp); // file descriptor to write to
5910  soap_set_mode(soap, SOAP_XML_GRAPH); // support id-ref w/o requiring SOAP
5911  soap_clr_mode(soap, SOAP_XML_TREE); // if set, clear
5912  if (soap_write_ns__record(soap, &pers1))
5913  ... // handle IO error
5914  fclose(fp);
5915  soap->sendfd = -1; // block further writing
5916  }
5917 ~~~
5918 
5919 which produces an XML document record.xml that is similar to:
5920 
5921 <div class="alt">
5922 ~~~{.xml}
5923  <ns:record xmlns:ns="urn:types" id="Joe">
5924  <name>Joe</name>
5925  <SSN>1234567890</SSN>
5926  <spouse id="Jane">
5927  <name>Jane</name>
5928  <SSN>1987654320</SSN>
5929  <spouse ref="#Joe"/>
5930  </spouse>
5931  </ns:record>
5932 ~~~
5933 </div>
5934 
5935 Deserialization of an XML document with a SOAP 1.1/1.2 encoded id-ref graph
5936 leads to the same non-termination problem when we later try to copy the data
5937 into unmanaged space:
5938 
5939 ~~~{.cpp}
5940  soap *soap = soap_new1(SOAP_XML_GRAPH); // support id-ref w/o SOAP
5941  ...
5942  ns__record pers1;
5943  FILE *fp = fopen("record.xml", "r");
5944  if (fp != NULL)
5945  {
5946  soap->recvfd = fileno(fp); // file descriptor to read from
5947  if (soap_read_ns__record(soap, &pers1))
5948  ... // handle IO error
5949  fclose(fp);
5950  soap->recvfd = -1; // block further reading
5951  }
5952  ...
5953  ns__record *pers3 = soap_dup_ns__record(NULL, NULL, &pers1); // BAD
5954  ns__record *pers4 = soap_dup_ns__record(soap, NULL, &pers1); // OK
5955  soap_set_mode(soap, SOAP_XML_TREE);
5956  ns__record *pers5 = soap_dup_ns__record(soap, NULL, &pers1); // OK
5957 ~~~
5958 
5959 Copying data with `soap_dup_T(soap)` into managed space is always safe. Copying
5960 into unmanaged space requires diligence. But deleting unmanaged data is easy
5961 with `soap_del_T()`.
5962 
5963 You can also use `soap_del_T()` to delete structures in C++, but only if these
5964 structures are created with `new` (and `new []` for arrays when applicable) for
5965 classes, structs, and class templates and with `malloc` for anything else, and
5966 the structures do NOT contain pointers to stack and static data.
5967 
5968 You can unlink one or more allocated objects from the managed heap to allow the
5969 object to live after `soap_destroy(soap)` and `soap_end(soap)` by using:
5970 
5971 - `void soap_unlink(struct soap *soap, void *ptr)`
5972 
5973 The unlinked heap-allocated data pointed to by `ptr` can be accessed after
5974 `soap_destroy(soap)` and `soap_end(soap)`. Do not forget to free the data with
5975 `delete ptr` (C++ class instance only) or with `free(ptr)` (non-class data).
5976 Be aware that `soap_unlink(soap, ptr)` does not perform a deep unlinkage. If
5977 `ptr` is a struct or class, pointer members will become invalid when pointing
5978 to objects on the managed heap. Use `soap_unlink(soap, ptr->member)` to unlink
5979 `member` as well.
5980 
5981 Finally, when data is allocated in managed memory heap space, either explicitly
5982 with the allocation functions shown above or by the soapcpp2-generated
5983 deserializers, you can delegate the management and deletion of this data to
5984 another `soap` context. That context will be responsible to delete the data
5985 with `soap_destroy(soap)` and `soap_end(soap)` later:
5986 
5987 - `void delegate_deletion(struct soap *soap_from, struct soap *soap_to)`
5988 
5989 This allows the `soap_from` context to be deleted with `soap_free(soap_from)`
5990 (assuming it is allocated with `soap_new()`, use `soap_done(soap_from)` when
5991 `soap_from` is stack-allocated) while the managed data remains intact. You
5992 can use this function any time, to delegate management and deletion to another
5993 context `soap_to` and then continue with the current context. You can also use
5994 different source `soap_from` contexts to delegate management and deletion to
5995 the other `soap_to` context. To mass delete all managed data, use
5996 `soap_destroy(soap_to)` followed by `soap_end(soap_to)`.
5997 
5998 🔝 [Back to table of contents](#)
5999 
6000 Context flags to initialize the soap struct {#flags}
6001 ===========================================
6002 
6003 There are several `soap` context initialization flags and context mode flags to
6004 control XML serialization at runtime. The flags are set with `soap_new1()` to
6005 allocate and initialize a new context:
6006 
6007 ~~~{.cpp}
6008  struct soap *soap = soap_new1(flag1 | flag2 | ... | flagn);
6009  ...
6010  soap_destroy(soap); // delete objects
6011  soap_end(soap); // delete other data and temp data
6012  soap_free(soap); // free context
6013 ~~~
6014 
6015 and with `soap_init1()` for stack-allocated contexts:
6016 
6017 ~~~{.cpp}
6018  struct soap soap;
6019  soap_init1(&soap, flag1 | flag2 | ... | flagn);
6020  ...
6021  soap_destroy(&soap); // delete objects
6022  soap_end(&soap); // delete other data and temp data
6023  soap_done(&soap); // clear context
6024 ~~~
6025 
6026 where `flag1`, `flag2`, ..., `flagn` is one of:
6027 
6028 - `SOAP_C_UTFSTRING`: enables all `std::string` and `char*` strings to
6029  contain UTF-8 content. This option is recommended.
6030 
6031 - `SOAP_C_NILSTRING`: treat empty strings as if they were NULL pointers, i.e.
6032  omits elements and attributes when empty.
6033 
6034 - `SOAP_XML_STRICT`: strictly validates XML while deserializing. Should not be
6035  used together with SOAP 1.1/1.2 encoding style of messaging. Use
6036  <b>`soapcpp2 -s`</b> option <b>`-s`</b> to hard code `SOAP_XML_STRICT` in the
6037  generated serializers. Not recommended with SOAP 1.1/1.2 encoding style
6038  messaging.
6039 
6040 - `SOAP_XML_INDENT`: produces indented XML.
6041 
6042 - `SOAP_XML_CANONICAL`: c14n canonocalization, removes unused `xmlns` bindings
6043  and adds them to appropriate places by applying c14n normalization rules.
6044  Should not be used together with SOAP 1.1/1.2 encoding style messaging.
6045 
6046 - `SOAP_XML_TREE`: write tree XML without id-ref, while pruning data structure
6047  cycles to prevent nontermination of the serializer for cyclic structures.
6048 
6049 - `SOAP_XML_GRAPH`: write graph (digraph and cyclic graphs with shared pointers
6050  to objects) using id-ref attributes. That is, XML with SOAP multi-ref
6051  encoded id-ref elements. This is a structure-preserving serialization format,
6052  because co-referenced data and also cyclic relations are accurately represented.
6053 
6054 - `SOAP_XML_DEFAULTNS`: uses xmlns default namespace declarations, assuming
6055  that the schema attribute form is "qualified" by default (be warned if it is
6056  not, since attributes in the null namespace will get bound to namespaces!).
6057 
6058 - `SOAP_XML_NIL`: emit empty element with <i>`xsi:nil`</i> for all NULL pointers
6059  serialized.
6060 
6061 - `SOAP_XML_IGNORENS`: the XML parser ignores XML namespaces, i.e. element and
6062  attribute tag names match independent of their namespace.
6063 
6064 - `SOAP_XML_NOTYPE`: removes all <i>`xsi:type`</i> attribuation. This option is usually
6065  not needed unless the receiver rejects all <i>`xsi:type`</i> attributes. This option
6066  may affect the quality of the deserializer, which relies on <i>`xsi:type`</i>
6067  attributes to distinguish base class instances from derived class instances
6068  transported in the XML payloads.
6069 
6070 - `SOAP_IO_CHUNK`: to enable HTTP chunked transfers.
6071 
6072 - `SOAP_IO_STORE`: full buffering of outbound messages.
6073 
6074 - `SOAP_ENC_ZLIB`: compress messages, requires compiling with option <b>`-DWITH_GZIP`</b> and
6075  linking with zlib using option <b>`-lz`</b>.
6076 
6077 - `SOAP_ENC_MIME`: enable MIME attachments, see
6078  [DIME/MIME/MTOM attachment binary types](#toxsd10-3).
6079 
6080 - `SOAP_ENC_MTOM`: enable MTOM attachments, see
6081  [DIME/MIME/MTOM attachment binary types](#toxsd10-3).
6082 
6083 @note C++ Web service proxy and service classes have their own `soap` context, either
6084 as a base class (with <b>`soapcpp2 -i`</b> option <b>`-i`</b>) or as a pointer member `soap` that points to
6085 a context (with <b>`soapcpp2 -j`</b> option <b>`-j`</b>). These contexts are allocated when the proxy or
6086 service is instantiated with context flags that are passed to the constructor.
6087 
6088 🔝 [Back to table of contents](#)
6089 
6090 Context parameter settings {#params}
6091 ==========================
6092 
6093 After allocation and initializtion of a `soap` context, several context
6094 parameters can be set (some parameters may require 2.8.31 or greater):
6095 
6096 - `unsigned int soap::maxlevel` is the maximum XML nesting depth levels that
6097  the parser permits. Default initialized to `SOAP_MAXLEVEL` (10000), which is
6098  a redefinable macro in <i>`gsoap/stdsoap2.h`</i>. Set `soap::maxlevel` to a
6099  lower value to restrict XML parsing nesting depth.
6100 
6101 - `long soap::maxlength` is the maximum string content length if not already
6102  constrained by an XML schema validation `maxLength` constraint. Zero means
6103  unlimited string lengths are permitted (unless restricted by XML schema
6104  `maxLength`). Default initialized to `SOAP_MAXLENGTH` (0), which is a
6105  redefinable macro in <i>`gsoap/stdsoap2.h`</i>. Set `soap::maxlength` to a
6106  positive value to restrict the number of (wide) characters in strings parsed,
6107  restrict hexBinary byte length, and restrict base64Binary byte length.
6108 
6109 - `size_t soap::maxoccurs` is the maximum number of array or container elements
6110  permitted by the parser. Must be greater than zero (0). Default initialized
6111  to `SOAP_MAXOCCURS` (100000), which is a redefinable macro in
6112  <i>`gsoap/stdsoap2.h`</i>. Set `soap::maxoccurs` to a positive value to
6113  restrict the number of array and container elements that can be parsed.
6114 
6115 - `soap::version` is the SOAP version used, with 0 for non-SOAP, 1 for SOAP1.1,
6116  and 2 for SOAP1.2. This value is normally set by web service operations, and
6117  is otherwise 0 (non-SOAP). Use `soap_set_version(struct soap*, short)` to
6118  set the value. This controls XML namespaces and SOAP id-ref serialization
6119  when applicable with an encodingStyle (see below).
6120 
6121 - `const char *soap::encodingStyle` is a string that is used with SOAP
6122  encoding, normally NULL for non-SOAP XML. Set this string to "" (empty
6123  string) to enable SOAP encoding style, which supports id-ref graph
6124  serialization (see also the `SOAP_XML_GRAPH` [context flag](#flags)).
6125 
6126 - `int soap::recvfd` is the file descriptor to read and parse source data from.
6127  Default initialized to 0 (stdin). See also [input and output](#io).
6128 
6129 - `int soap::sendfd` is the file descriptor to write data to. Default
6130  initialized to 1 (stdout). See also [input and output](#io).
6131 
6132 - `const char *is` for C: string to read and parse source data from, overriding
6133  the `recvfd` source. Normally NULL. This value must be reset to NULL or
6134  the parser will continue to read from this string content until the NUL
6135  character. See also [input and output](#io).
6136 
6137 - `std::istream *is` for C++: an input stream to read and parse source data
6138  from, overriding the `recvfd` source. Normally NULL. This value must be
6139  reset to NULL or the parser will continue to read from this stream until EOF.
6140  See also [input and output](#io).
6141 
6142 - `const char **os` for C: points to a string (a `const char *`) that will be
6143  set to point to the string output. Normally NULL. This value must be reset
6144  to NULL or the next output will result in reassigning the pointer to point to
6145  the next string that is output. The strings are automatically deallocated by
6146  `soap_end(soap)`. See also [input and output](#io).
6147 
6148 - `std::ostream *os` for C++: an output stream to write output to. Normally
6149  NULL. This value must be reste to NULL or the next output will be send to
6150  this stream. See also [input and output](#io).
6151 
6152 🔝 [Back to table of contents](#)
6153 
6154 Error handling and reporting {#errors}
6155 ============================
6156 
6157 The gSOAP API functions return `SOAP_OK` (zero) or a non-zero error code. The
6158 error code is stored in `int soap::error` of the current `soap` context.
6159 Error messages can be displayed with:
6160 
6161 - `void soap_stream_fault(struct soap*, std::ostream &os)` for C++ only, prints
6162  the error message to an output stream.
6163 
6164 - `void soap_print_fault(struct soap*, FILE *fd)` prints the error message to a
6165  FILE descriptor.
6166 
6167 - `void soap_sprint_fault(struct soap*, char *buf, size_t len)` saves the error
6168  message to a fixed-size buffer allocated with a maximum length.
6169 
6170 - `void soap_print_fault_location(struct soap*, FILE *fd)` prints the location
6171  and part of the XML where the parser encountered an error.
6172 
6173 C++ exceptions are never raised by the engine or serializers, even when data is
6174 allocated.
6175 
6176 A `SOAP_EOM` error code is returned when memory was exhausted during
6177 processing of input and/or output of data.
6178 
6179 An EOF (`SOAP_EOF` or -1) error code is returned when the parser has hit EOF
6180 but expected more input, or when socket communications timed out. In addition
6181 to the `SOAP_EOF` error, the `int soap::errnum` of the `soap` context is
6182 set to the `errno` value of the operation that failed. For timeouts, the
6183 `soap::ernum` value is always 0 instead of an `errno` error code.
6184 
6185 Use `soap_xml_error_check(soap->error)` to check for XML errors. This returns
6186 true (non-zero) when a parsing and validation error has occurred.
6187 
6188 For example:
6189 
6190 ~~~{.cpp}
6191  #include <sstream>
6192 
6193  struct soap *soap = soap_new1(SOAP_XML_INDENT | SOAP_XML_STRICT | SOAP_XML_TREE);
6194  struct ns__record person;
6195  std::stringstream ss;
6196  ss.str("..."); // XML to parse
6197  soap->is = &ss;
6198  if (soap_read__ns__record(soap, &person))
6199  {
6200  if (soap_xml_error_check(soap->error))
6201  std::cerr << "XML parsing error!" << std::endl;
6202  else
6203  soap_stream_fault(soap, std::cerr);
6204  }
6205  else
6206  {
6207  ... // all OK, use person record
6208  }
6209  soap_destroy(soap); // delete objects
6210  soap_end(soap); // delete other data and temp data
6211  soap_free(soap); // free context
6212 ~~~
6213 
6214 When deploying your application on UNIX and Linux systems, UNIX signal handlers
6215 should be added to your code handle signals, in particular `SIGPIPE`:
6216 
6217 ~~~{.cpp}
6218  signal(SIGPIPE, sigpipe_handler);
6219 ~~~
6220 
6221 where the `sigpipe_handler` is a function:
6222 
6223 ~~~{.cpp}
6224  void sigpipe_handler(int x) { }
6225 ~~~
6226 
6227 Other UNIX signals may have to be handled as well.
6228 
6229 The engine is designed for easy memory cleanup after being interrupted. Use
6230 `soap_destroy(soap)` and `soap_end(soap)`, after which the `soap` context can
6231 be reused.
6232 
6233 🔝 [Back to table of contents](#)
6234 
6235 Features and limitations {#features}
6236 ========================
6237 
6238 In general, to use the generated code:
6239 
6240 - Make sure to `#include "soapH.h"` in your code and also define a namespace
6241  table or `#include "ns.nsmap"` with the generated table, where `ns` is the
6242  namespace prefix for services.
6243 
6244 - Use <b>`soapcpp2 -j`</b> option <b>`-j`</b> (C++ only) to generate C++ proxy and service objects.
6245  The auto-generated files include documented inferfaces. Compile with
6246  <i>`soapC.cpp`</i> and link with <b>`-lgsoap++`</b>, or alternatively compile
6247  <i>`gsoap/stdsoap2.cpp`</i>.
6248 
6249 - Without <b>`soapcpp2 -j`</b> option <b>`-j`</b>: client-side uses the auto-generated
6250  <i>`soapClient.cpp`</i> and <i>`soapC.cpp`</i> (or C versions of those).
6251  Compile and link with <b>`-lgsoap++`</b> (<b>`-lgsoap`</b> for C), or
6252  alternatively compile <i>`gsoap/stdsoap2.cpp`</i> (<i>`gsoap/stdsoap2.c`</i>
6253  for C).
6254 
6255 - Without <b>`soapcpp2 -j`</b> option <b>`-j`</b>: server-side uses the
6256  auto-generated <i>`soapServer.cpp`</i> and <i>`soapC.cpp`</i> (or C versions
6257  of those). Compile and link with <b>`-lgsoap++`</b> (<b>`-lgsoap`</b> for
6258  C), or alternatively compile <i>`gsoap/stdsoap2.cpp`</i> (<i>`stdsoap2.c`</i>
6259  for C).
6260 
6261 - Use `soap_new()` or `soap_new1(int flags)` to allocate and initialize a
6262  heap-allocated `soap` context with or without flags. Delete this `soap` context with
6263  `soap_free(struct soap*)`, but only after `soap_destroy(struct soap*)` and
6264  `soap_end(struct soap*)`.
6265 
6266 - Use `soap_init(struct *soap)` or `soap_init1(struct soap*, int flags)` to
6267  initialize a stack-allocated `soap` context with or without flags. End the use of
6268  this context with `soap_done(struct soap*)`, but only after
6269  `soap_destroy(struct soap*)` and `soap_end(struct soap*)`.
6270 
6271 Additional notes with respect to the wsdl2h and soapcpp2 tools:
6272 
6273 - Nested classes, structs, and unions in a interface header file are unnested
6274  by soapcpp2.
6275 
6276 - Use `#import "file.h"` instead of `#include` to import other header files in
6277  a interface header file for soapcpp2. The `#include`, `#define`, and
6278  `#pragma` are accepted by soapcpp2, but are moved to the very start of the
6279  generated code for the C/C++ compiler to include before all generated
6280  definitions. Often it is useful to add an `#include` with a
6281  [volatile type](#toxsd9-2) that includes the actual type declaration, and to
6282  ensure transient types are declared when these are used in a data binding
6283  interface declared in a interface header file for soapcpp2.
6284 
6285 - To remove any SOAP-specific bindings, use <b>`soapcpp2 -0`</b> option <b>`-0`</b>.
6286 
6287 - A interface header file for soapcpp2 should not include any code statements,
6288  only data type declarations. This includes constructor initialization lists
6289  that are not permitted. Use member initializations instead.
6290 
6291 - C++ namespaces are supported. Use <b>`wsdl2h -qname`</b> option
6292  <b>`-qname`</b> to add C++ namespace `name`. Or add a `namespace name { ... }`
6293  to the header file, but the `{ ... }` must cover the entire
6294  header file content from begin to end.
6295 
6296 - Optional XML DOM support can be used to store mixed content or literal XML
6297  content. Otherwise, mixed content may be lost. Use <b>`wsdl2h -d`</b>
6298  option <b>`-d`</b> for XML DOM support and compile and link with
6299  <i>`gsoap/dom.c`</i> or <i>`gsoap/dom.cpp`</i>. For details,
6300  see [XML DOM and XPath](http://www.genivia.com/doc/dom/html).
6301 
6302 🔝 [Back to table of contents](#)
6303 
6304 Removing SOAP namespaces from XML payloads {#nsmap}
6305 ==========================================
6306 
6307 The soapcpp2 tool generates a <i>`.nsmap`</i> file that includes two bindings for SOAP
6308 namespaces. We can remove all SOAP namespaces (and SOAP processing logic) with
6309 <b>`soapcpp2 -0`</b> option <b>`-0`</b> or by simply setting the two entries to NULL:
6310 
6311 ~~~{.cpp}
6312  struct Namespace namespaces[] =
6313  {
6314  {"SOAP-ENV", NULL, NULL, NULL},
6315  {"SOAP-ENC", NULL, NULL, NULL},
6316  ...
6317  };
6318 ~~~
6319 
6320 Once the <i>`.nsmap`</i> is generated, you can copy-paste the content into your
6321 project code. However, if we rerun wsdl2h on updated WSDL/XSD files or
6322 <i>`typemap.dat`</i> declarations then we need to use the updated table.
6323 
6324 In cases that no XML namespaces are used at all, for example with
6325 [XML-RPC](http://www.genivia.com/doc/xml-rpc-json/html), you may use an empty
6326 namespace table:
6327 
6328 ~~~{.cpp}
6329  struct Namespace namespaces[] = {{NULL,NULL,NULL,NULL}};
6330 ~~~
6331 
6332 However, beware that any built-in xsi attributes that are rendered will lack
6333 the proper namespace binding. At least we suggest to use `SOAP_XML_NOTYPE` for
6334 this reason.
6335 
6336 🔝 [Back to table of contents](#)
6337 
6338 Examples {#examples}
6339 ========
6340 
6341 Select the project files below to peruse the source code examples.
6342 
6343 🔝 [Back to table of contents](#)
6344 
6345 Source files
6346 ------------
6347 
6348 - <i>`address.xsd`</i> Address book schema
6349 - <i>`address.cpp`</i> Address book app (reads/writes address.xml file)
6350 - <i>`addresstypemap.dat`</i> Schema namespace prefix name preference for wsdl2h
6351 - <i>`graph.h`</i> Graph data binding (tree, digraph, cyclic graph)
6352 - <i>`graph.cpp`</i> Test graph serialization as tree, digraph, and cyclic
6353 
6354 🔝 [Back to table of contents](#)
6355 
6356 Generated files
6357 ---------------
6358 
6359 - <i>`address.h`</i> data binding interface generated from address.xsd
6360 - <i>`addressStub.h`</i> C++ data binding definitions
6361 - <i>`addressH.h`</i> Serializers
6362 - <i>`addressC.cpp`</i> Serializers
6363 - <i>`address.xml`</i> Address book data generated by address app
6364 - <i>`graphStub.h`</i> C++ data binding definitions
6365 - <i>`graphH.h`</i> Serializers
6366 - <i>`graphC.cpp`</i> Serializers
6367 - <i>`g.xsd`</i> XSD schema with <i>`g:Graph`</i> complexType
6368 - <i>`g.nsmap`</i> xmlns bindings namespace mapping table
6369 
6370 🔝 [Back to table of contents](#)
6371 
6372 Build steps
6373 -----------
6374 
6375 Building the AddressBook example:
6376 
6377  wsdl2h -g -taddresstypemap.dat address.xsd
6378  soapcpp2 -0 -C -S -paddress -I../../import address.h
6379  c++ -I../.. address.cpp addressC.cpp -o address -lgsoap++
6380 
6381 Using <b>`wsdl2h -g -taddresstypemap.dat`</b> option <b>`-g`</b> produces
6382 bindings for global (root) elements in addition to types and option
6383 <b>`-taddresstypemap.dat`</b> specifies a mapping file, see further below.
6384 
6385 In this case the root element <i>`a:address-book`</i> is bound to `_a__address_book`.
6386 The complexType <i>`a:address`</i> is bound to class `a__address`, which is also the
6387 type of `_a__address_book`. This option is not required, but allows you to use
6388 global element tag names when referring to their serializers, instead of their
6389 type name. Using <b>`soapcpp2 -0 -C -S -paddress`</b> option <b>`-0`</b> removes the
6390 SOAP protocol and the combination of the two options <b>`-C`</b> and
6391 <b>`-S`</b> removes client and server code generation (using option <b>`-C`</b>
6392 alone generates client code and using option <b>`-S`</b> alone generates server
6393 code). Option <b>`-paddress`</b> renames the output <i>`soap`</i>-prefixed files to
6394 <i>`address`</i>-prefixed files.
6395 
6396 See the <i>`address.cpp`</i> implementation and [related pages](pages.html).
6397 
6398 The <i>`addresstypemap.dat`</i> file specifies the XML namespace prefix for the
6399 bindings:
6400 
6401  # Bind the address book schema namespace to prefix 'a'
6402 
6403  a = "urn:address-book-example"
6404 
6405  # By default the xsd:dateTime schema type is translated to time_t
6406  # To map xsd:dateTime to struct tm, enable the following line:
6407 
6408  # xsd__dateTime = #import "../../custom/struct_tm.h"
6409 
6410  # ... and compile/link with custom/struct_tm.c
6411 
6412 The DOB field is a <i>`xsd:dateTime`</i>, which is bound to `time_t` by default. To
6413 change this to `struct tm`, enable the import of the `xsd__dateTime` custom
6414 serializer by uncommenting the definition of `xsd__dateTime` in
6415 <i>`addresstypemap.dat`</i>. Then change `soap_dateTime2s` to `soap_xsd__dateTime2s`
6416 in the code.
6417 
6418 Building the graph serialization example:
6419 
6420  soapcpp2 -C -S -pgraph -I../../import graph.h
6421  c++ -I../.. graph.cpp graphC.cpp -o graph -lgsoap++
6422 
6423 To compile without using the <b>`-lgsoap++`</b> library: simply compile
6424 <i>`stdsoap2.cpp`</i> together with the above.
6425 
6426 🔝 [Back to table of contents](#)
6427 
6428 Usage
6429 -----
6430 
6431 To execute the AddressBook example:
6432 
6433  ./address
6434 
6435 To execute the Graph serialization example:
6436 
6437  ./graph
6438