Genivia Home Documentation
README.md Source File

updated Mon Feb 22 2016
 
README.md
Go to the documentation of this file.
1 
2 XML Data Bindings {#mainpage}
3 =================
4 
5 [TOC]
6 
7 Introduction {#intro}
8 ============
9 
10 This is a detailed overview of the gSOAP XML data bindings concepts, usage, and
11 implementation. At the end of this document two examples are given to
12 illustrate the application of XML data bindings.
13 
14 The first simple example `address.cpp` shows how to use wsdl2h to bind an XML
15 schema to C++. The C++ application reads and writes an XML file into and from
16 a C++ "address book" data structure. The C++ data structure is an STL vector
17 of address objects.
18 
19 The second example `graph.cpp` shows how XML is serialized as a tree, digraph,
20 and cyclic graph. The digraph and cyclic graph serialization rules are similar
21 to SOAP 1.1/1.2 encoded multi-ref elements with id-ref attributes to link
22 elements through IDREF XML references, creating a an XML graph with pointers to
23 XML nodes.
24 
25 These examples demonstrate XML data bindings only for relatively simple data
26 structures and types. The gSOAP tools support more than just these type of
27 structures to serialize in XML. There are practically no limits to
28 enable XML serialization of C and C++ types.
29 
30 Support for XML schema components is unlimited. The wsdl2h tool maps schemas
31 to C and C++ using built-in intuitive mapping rules, while allowing the
32 mappings to be customized using a `typemap.dat` file with mapping instructions
33 for wsdl2h.
34 
35 The information in this document is applicable to gSOAP 2.8.26 and higher, which
36 supports C++11 features. However, C++11 is not required to use this material
37 and the examples included, unless we need smart pointers and scoped
38 enumerations. While most of the examples in this document are given in C++,
39 the concepts also apply to C with the exception of containers, smart pointers,
40 classes and their methods. None of these exceptions limit the use of the
41 gSOAP tools for C in any way.
42 
43 The data binding concepts described in this document were first envisioned in
44 1999 by Prof. Robert van Engelen at the Florida State University. An
45 implementation was created in 2000, named "stub/skeleton compiler". The first
46 articles on its successor version "gSOAP" appeared in 2002. The principle of
47 mapping XSD components to C/C++ types and vice versa is now widely adopted in
48 systems and programming languages, including Java web services and by C# WCF.
49 
50 We continue to be committed to our goal to empower C/C++ developers with
51 powerful autocoding tools for XML. Our commitment started in the very early
52 days of SOAP by actively participating in
53 [SOAP interoperability testing](http://www.whitemesa.com/interop.htm),
54 participating in the development and testing of the
55 [W3C XML Schema Patterns for Databinding Interoperability](http://www.w3.org/2002/ws/databinding),
56 and continues by contributing to the development of
57 [OASIS open standards](https://www.oasis-open.org) in partnership with leading
58 IT companies.
59 
60 Mapping WSDL and XML schemas to C/C++ {#tocpp}
61 =====================================
62 
63 To convert WSDL and XML schemas (XSD files) to code, use the wsdl2h command to
64 generate the data binding interface code that is saved to a special gSOAP
65 header file with WSDL service declarations and the data binding interface:
66 
67  wsdl2h [options] -o file.h ... XSD and WSDL files ...
68 
69 This command converts WSDL and XSD files to C++ (or pure C with wsdl2h option
70 `-c`) and saves the data binding interface to a gSOAP header file `file.h` that
71 uses familiar C/C++ syntax extended with `//gsoap` [directives](#directives)
72 and annotations. Notational conventions are used in the data binding interface
73 to declare serializable C/C++ types and functions for Web service operations.
74 
75 The WSDL 1.1/2.0, SOAP 1.1/1.2, and XSD 1.0/1.1 standards are supported by the
76 gSOAP tools. In addition, the most popular WS specifications are also
77 supported, including WS-Addressing, WS-ReliableMessaging, WS-Discovery,
78 WS-Security, WS-Policy, WS-SecurityPolicy, and WS-SecureConversation.
79 
80 This document focusses on XML data bindings. XML data bindings for C/C++ bind
81 XML schema types to C/C++ types. So integers in XML are bound to C integers,
82 strings in XML are bound to C or C++ strings, complex types in XML are bound to
83 C structs or C++ classes, and so on.
84 
85 A data binding is dual. Either you start with WSDLs and/or XML schemas that
86 are mapped to equivalent C/C++ types, or you start with C/C++ types that are
87 mapped to XSD types. Either way, the end result is that you can serialize
88 C/C++ types in XML such that your XML is an instance of XML schema(s) and is
89 validated against these schema(s).
90 
91 This covers all of the following standard XSD components with their optional
92 attributes and properties:
93 
94 | XSD Component | Attributes and Properties |
95 | -------------- | ------------------------------------------------------------------------------------------------------------------- |
96 | schema | targetNamespace, version, elementFormDefault, attributeFormDefault, defaultAttributes |
97 | attribute | name, ref, type, use, default, fixed, form, targetNamespace, wsdl:arrayType |
98 | element | name, ref, type, default, fixed, form, nillable, abstract, substitutionGroup, minOccurs, maxOccurs, targetNamespace |
99 | simpleType | name |
100 | complexType | name, abstract, mixed, defaultAttributesApply |
101 | all | |
102 | choice | minOccurs, maxOccurs |
103 | sequence | minOccurs, maxOccurs |
104 | group | name, ref, minOccurs, maxOccurs |
105 | attributeGroup | name, ref |
106 | any | minOccurs, maxOccurs |
107 | anyAttribute | |
108 
109 And also the following standard XSD directives are covered:
110 
111 | Directive | Description |
112 | ---------- | ---------------------------------------------------------- |
113 | import | Imports a schema into the importing schema for referencing |
114 | include | Include schema component definitions into a schema |
115 | override | Override by replacing schema component definitions |
116 | redefine | Extend or restrict schema component definitions |
117 | annotation | Annotates a component |
118 
119 The XSD facets and their mappings to C/C++ are:
120 
121 | XSD Facet | Maps to |
122 | -------------- | ------------------------------------------------------------------------------------------- |
123 | enumeration | `enum` |
124 | simpleContent | class/struct wrapper with `__item` member |
125 | complexContent | class/struct |
126 | list | `enum*` bitmask (`enum*` enumerates up to 64 bit masks) |
127 | extension | class/struct inheritance/extension |
128 | restriction | `typedef` and class/struct inheritance/redeclaration |
129 | length | `typedef` with restricted content length annotation |
130 | minLength | `typedef` with restricted content length annotation |
131 | maxLength | `typedef` with restricted content length annotation |
132 | minInclusive | `typedef` with numerical value range restriction annotation |
133 | maxInclusive | `typedef` with numerical value range restriction annotation |
134 | minExclusive | `typedef` with numerical value range restriction annotation |
135 | maxExclusive | `typedef` with numerical value range restriction annotation |
136 | precision | `typedef` with pattern annotation (pattern used for output, but input is not validated) |
137 | scale | `typedef` with pattern annotation (pattern used for output, but input is not validated) |
138 | totalDigits | `typedef` with pattern annotation (pattern used for output, but input is not validated) |
139 | fractionDigits | `typedef` with pattern annotation (pattern used for output, but input is not validated) |
140 | pattern | `typedef` with pattern annotation (define `soap::fsvalidate` callback to validate patterns) |
141 | union | string with union of values
142 
143 All primitive XSD types are supported, including but not limited to the
144 following XSD types:
145 
146 | XSD Type | Maps to |
147 | ---------------- | --------------------------------------------------------------------------------- |
148 | any/anyType | `_XML` string with literal XML content (or enable DOM with wsdl2h option `-d`) |
149 | anyURI | string (i.e. `char*`, `wchar_t*`, `std::string`, `std::wstring`) |
150 | string | string (i.e. `char*`, `wchar_t*`, `std::string`, `std::wstring`) |
151 | boolean | `bool` (C++) or `enum xsd__boolean` (C) |
152 | byte | `char` (i.e. `int8_t`) |
153 | short | `short` (i.e. `int16_t`) |
154 | int | `int` (i.e. `int32_t`) |
155 | long | `LONG64` (i.e. `long long` and `int64_t`) |
156 | unsignedByte | `unsigned char` (i.e. `uint8_t`) |
157 | unsignedShort | `unsigned short` (i.e. `uint16_t`) |
158 | unsignedInt | `unsigned int` (i.e. `uint32_t`) |
159 | unsignedLong | `ULONG64` (i.e. `unsigned long long` and `uint64_t`) |
160 | float | `float` |
161 | double | `double` |
162 | integer | string or `#import "custom/int128.h"` to use 128 bit `xsd__integer` |
163 | decimal | string or `#import "custom/long_double.h"` to use `long double` |
164 | precisionDecimal | string |
165 | duration | string or `#import "custom/duration.h"` to use 64 bit `xsd__duration` |
166 | dateTime | `time_t` or `#import "custom/struct_tm.h"` to use `struct tm` for `xsd__dateTime` |
167 | time | string or `#import "custom/long_time.h"` to use 64 bit `xsd__time` |
168 | date | string or `#import "custom/struct_tm_date.h"` to use `struct tm` for `xsd__date` |
169 | hexBinary | special class/struct `xsd__hexBinary` |
170 | base64Bianry | special class/struct `xsd__base64Binary` |
171 | QName | `_QName` string (URI normalization rules are applied) |
172 
173 All other primitive XSD types not listed above are mapped to strings, by
174 wsdl2h generating a typedef to string for these types. For example,
175 `xsd:token` is bound to a C++ or C string:
176 
177 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
178  typedef std::string xsd__token; // C++
179  typedef char *xsd__token; // C (wsdl2h option -c)
180 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
181 
182 This associates a compatible value space to the type with the appropriate XSD
183 type name used by the soapcpp2-generated serializers.
184 
185 It is possible to remap types by adding the appropriate mapping rules to
186 `typemap.dat` as we will explain in more detail in the next section.
187 
188 Imported custom serializers are intended to extend the C/C++ type bindings when
189 the default binding to string is not satisfactory to your taste and if the
190 target platform supports these C/C++ types. To add custom serializers to
191 `typemap.dat` for wsdl2h, see [adding custom serializers](#custom) below.
192 
193 Using typemap.dat to customize data bindings {#typemap}
194 ============================================
195 
196 Use a `typemap.dat` file to redefine namespace prefixes and to customize type
197 bindings for the the generated header files produced by the wsdl2h tool. The
198 `typemap.dat` is the default file processed by wsdl2h. Use wsdl2h option `-t`
199 to specify a different file.
200 
201 Declarations in `typemap.dat` can be broken up over multiple lines by
202 continuing on the next line by ending each line to be continued with a
203 backslash `\`. The limit is 4095 characters per line, whether the line is
204 broken up or not.
205 
206 XML namespace bindings {#typemap1}
207 ----------------------
208 
209 The wsdl2h tool generates C/C++ type declarations that use `ns1`, `ns2`, etc.
210 as schema-binding URI prefixes. These default prefixes are generated somewhat
211 arbitrarily for each schema targetNamespace URI, meaning that their ordering
212 may change depending on the WSDL and XSD order of processing with wsdl2h.
213 
214 Therefore, it is **strongly recommended** to declare your own prefix for each
215 schema URI in `typemap.dat` to reduce maintaince effort of your code. This
216 is more robust when anticipating possible changes of the schema(s) and/or the
217 binding URI(s) and/or the tooling algorithms.
218 
219 The first and foremost important thing to do is to define prefix-URI bindings
220 for our C/C++ code by adding the following line(s) to our `typemap.dat` or make
221 a copy of this file and add the line(s) that bind our choice of prefix name to
222 each URI:
223 
224  prefix = "URI"
225 
226 For example:
227 
228  g = "urn:graph"
229 
230 This produces `g__name` C/C++ type names that are bound to the "urn:graph"
231 schema by association of `g` to the generated C/C++ types.
232 
233 This means that `<g:name xmlns:g="urn:graph">` is parsed as an instance of a
234 `g__name` C/C++ type. Also `<x:name xmlns:x="urn:graph">` parses as an
235 instance of `g__name`, because the prefix `x` has the same URI value
236 `urn:graph`. Prefixes in XML have local scopes (like variables in a block).
237 
238 The first run of wsdl2h will reveal the URIs, so you do not need to search
239 WSDLs and XSD files for all of the target namespaces. Just copy them from the
240 generated header file after the first run into `typemap.dat` for editing.
241 
242 XSD type bindings {#typemap2}
243 -----------------
244 
245 Custom C/C++ type bindings can be declared in `typemap.dat` to associate C/C++
246 types with specific schema types. These type bindings have four parts:
247 
248  prefix__type = declaration | use | ptruse
249 
250 where
251 
252 - `prefix__type` is the schema type to be customized (the `prefix__type` name
253  uses the common double underscore naming convention);
254 - `declaration` declares the C/C++ type in the wsdl2h-generated header file.
255  This part can be empty if no explicit declaration is needed;
256 - `use` is an optional part that specifies how the C/C++ type is used in the
257  code. When omitted, it is the same as `prefix__type`;
258 - `ptruse` is an optional part that specifies how the type is used as a
259  pointer type. By default it is the `use` type name with a `*` or C++11
260  `std::shared_ptr<>` when enabled (see further below).
261 
262 For example, to map `xsd:duration` to a `long long` (`LONG64`) type that holds
263 millisecond duration values, we can use the custom serializer declared in
264 `custom/duration.h` by adding the following line to `typemap.dat`:
265 
266  xsd__duration = #import "custom/duration.h"
267 
268 Here, we omitted the second field, because `xsd__duration` is the name that
269 wsdl2h uses to identify and use this type for our code. The third field is
270 omitted to let wsdl2h use `xsd__duration *` for pointers or
271 `std::shared_ptr<xsd__duration>` if smart pointers are enabled.
272 
273 To map `xsd:string` to `wchar_t*` wide strings:
274 
275  xsd__string = | wchar_t* | wchar_t*
276 
277 Note that the first field is empty, because `wchar_t` is a C type and does not
278 need to be declared. A `ptruse` field is given so that we do not end up
279 generating the wrong pointer types, such as `wchar_t**` and
280 `std::shared_ptr<wchar_t>`.
281 
282 When the auto-generated declaration should be preserved but the `use` or
283 `ptruse` fields replaced, then we use an ellipsis for the declaration part:
284 
285  prefix__type = ... | use | ptruse
286 
287 This is useful to map schema polymorphic types to C types for example, where we
288 need to be able to both handle a base type and its extensions as per schema
289 extensibility. Say we have a base type called ns:base that is extended, then we
290 can remap this to a C type that permits referening the extended types via a
291 `void*` as follows:
292 
293  ns__base = ... | int __type_base; void*
294 
295 such that `__type_base` and `void*` will be used to (de)serialize any data
296 type, including base and its derived types. The `__type_base` integer is set
297 to a `SOAP_TYPE_T` value to indicate what type of data the `void*` pointer
298 points to.
299 
300 Custom serializers for XSD types {#custom}
301 --------------------------------
302 
303 In the previous part we saw how a custom serializer is used to bind
304 `xsd:duration` to a `long long` (`LONG64` or `int64_t`) type to store millisecond
305 duration values:
306 
307  xsd__duration = #import "custom/duration.h"
308 
309 The `xsd__duration` type is an alias of `long long` (`LONG64` or `int64_t`).
310 
311 While wsdl2h will use this binding declared in `typemap.dat` automatically, you
312 will also need to compile `custom/duration.c`. Each custom serializer has a
313 header file and an implementation file written in C. You can compile these in
314 C++ (rename files to `.cpp` if needed).
315 
316 We will discuss the custom serializers that are available to you.
317 
318 ### xsd:integer {#custom-1}
319 
320 The wsdl2h tool maps `xsd:integer` to a string by default. To map `xsd:integer` to
321 the 128 bit big int type `__int128_t`:
322 
323  xsd__integer = #import "custom/int128.h"
324 
325 The `xsd__integer` type is an alias of `__int128_t`.
326 
327 @warning Beware that the `xsd:integer` value space of integers is in principle
328 unbounded and values can be of arbitrary length. A value range fault
329 `SOAP_TYPE` (value exceeds native representation) or `SOAP_LENGTH` (value
330 exceeds range bounds) will be thrown by the deserializer if the value is out of
331 range.
332 
333 Other XSD integer types that are restrictions of `xsd:integer`, are
334 `xsd:nonNegativeInteger` and `xsd:nonPositiveInteger`, which are further restricted
335 by `xsd:positiveInteger` and `xsd:negativeInteger`. To bind these types to
336 `__int128_t` we should also add the following definitions to `typemap.dat`:
337 
338  xsd__nonNegativeInteger = typedef xsd__integer xsd__nonNegativeInteger 0 : ;
339  xsd__nonPositiveInteger = typedef xsd__integer xsd__nonPositiveInteger : 0 ;
340  xsd__positiveInteger = typedef xsd__integer xsd__positiveInteger 1 : ;
341  xsd__negativeInteger = typedef xsd__integer xsd__negativeInteger : -1 ;
342 
343 @note If `__int128_t` 128 bit integers are not supported on your platform and if it
344 is certain that `xsd:integer` values are within 64 bit value bounds for your
345 application's use, then you can map this type to `LONG64`:
346 
347  xsd__integer = typedef LONG64 xsd__integer;
348 
349 @note Again, a value range fault `SOAP_TYPE` or `SOAP_LENGTH` will be thrown by
350 the deserializer if the value is out of range.
351 
352 @see Section [numerical types](#toxsd5).
353 
354 ### xsd:decimal {#custom-2}
355 
356 The wsdl2h tool maps `xsd:decimal` to a string by default. To map `xsd:decimal` to
357 extended precision floating point:
358 
359  xsd__decimal = #import "custom/long_double.h" | long double
360 
361 By contrast to all other custom serializers, this serializer enables `long
362 double` natively without requiring a new binding name (`xsd__decimal` is NOT
363 defined).
364 
365 If your system supports `<quadmath.h>` quadruple precision floating point
366 `__float128`, you can map `xsd:decimal` to `xsd__decimal` that is an alias of
367 `__float128`:
368 
369  xsd__decimal = #import "custom/float128.h"
370 
371 @warning Beware that `xsd:decimal` is in principle a decimal value with arbitraty
372 lengths. A value range fault `SOAP_TYPE` will be thrown by the deserializer if
373 the value is out of range.
374 
375 In the XML payload the special values `INF`, `-INF`, `NaN` represent plus or
376 minus infinity and not-a-number, respectively.
377 
378 @see Section [numerical types](#toxsd5).
379 
380 ### xsd:dateTime {#custom-3}
381 
382 The wsdl2h tool maps `xsd:dateTime` to `time_t` by default.
383 
384 The trouble with `time_t` when represented as 32 bit `long` integers is that it
385 is limited to dates between 1970 and 2038. A 64 bit `time_t` is safe to use if
386 the target platform supports it, but lack of 64 bit `time_t` portability may
387 still cause date range issues.
388 
389 For this reason `struct tm` should be used to represent wider date ranges. This
390 custom serializer avoids using date and time information in `time_t`. You get
391 the raw date and time information. You only lose the day of the week
392 information. It is always Sunday (`tm_wday=0`).
393 
394 To map `xsd:dateTime` to `xsd__dateTime` which is an alias of `struct tm`:
395 
396  xsd__dateTime = #import "custom/struct_tm.h"
397 
398 If the limited date range of `time_t` is not a problem but you want to increase
399 the time precision with fractional seconds, then we suggest to map `xsd:dateTime`
400 to `struct timeval`:
401 
402  xsd__dateTime = #import "custom/struct_timeval.h"
403 
404 If the limited date range of `time_t` is not a problem but you want to use the
405 C++11 time point type `std::chrono::system_clock::time_point` (which internally
406 uses `time_t`):
407 
408  xsd__dateTime = #import "custom/chrono_time_point.h"
409 
410 Again, we should make sure that the dates will not exceed the date range when
411 using the default `time_t` binding for `xsd:dateTime` or when binding
412 `xsd:dateTime` to `struct timeval` or to `std::chrono::system_clock::time_point`.
413 These are safe to use in applications that use `xsd:dateTime` to record date
414 stamps within a given window. Otherwise, we recommend the `struct tm` custom
415 serializer. You could even map `xsd:dateTime` to a plain string (use `char*` with
416 C and `std::string` with C++). For example:
417 
418  xsd__dateTime = | char*
419 
420 @see Section [date and time types](#toxsd7).
421 
422 ### xsd:date {#custom-4}
423 
424 The wsdl2h tool maps `xsd:date` to a string by default. We can map `xsd:date` to
425 `struct tm`:
426 
427  xsd__date = #import "custom/struct_tm_date.h"
428 
429 The `xsd__date` type is an alias of `struct tm`. The serializer ignores the
430 time part and the deserializer only populates the date part of the struct,
431 setting the time to 00:00:00. There is no unreasonable limit on the date range
432 because the year field is stored as an integer (`int`).
433 
434 @see Section [date and time types](#toxsd7).
435 
436 ### xsd:time {#custom-5}
437 
438 The wsdl2h tool maps `xsd:time` to a string by default. We can map `xsd:time` to
439 an `unsigned long long` (`ULONG64` or `uint64_t`) integer with microsecond time
440 precision:
441 
442  xsd__time = #import "custom/long_time.h"
443 
444 This type represents 00:00:00.000000 to 23:59:59.999999, from `0` to an upper
445 bound of `86399999999`. A microsecond resolution means that a 1 second
446 increment requires an increment of 1000000 in the integer value. The serializer
447 adds a UTC time zone.
448 
449 @see Section [date and time types](#toxsd7).
450 
451 ### xsd:duration {#custom-6}
452 
453 The wsdl2h tool maps `xsd:duration` to a string by default, unless `xsd:duration`
454 is mapped to a `long long` (`LONG64` or `int64_t`) type with with millisecond
455 (ms) time duration precision:
456 
457  xsd__duration = #import "custom/duration.h"
458 
459 The `xsd__duration` type is a 64 bit signed integer that can represent
460 106,751,991,167 days forwards (positive) and backwards (negative) in time in
461 increments of 1 ms (1/1000 of a second).
462 
463 Rescaling of the duration value by may be needed when adding the duration value
464 to a `time_t` value, because `time_t` may or may not have a seconds resolution,
465 depending on the platform and possible changes to `time_t`.
466 
467 Rescaling is done automatically when you add a C++11 `std::chrono::nanoseconds`
468 value to a `std::chrono::system_clock::time_point` value. To use
469 `std::chrono::nanoseconds` as `xsd:duration`:
470 
471  xsd__duration = #import "custom/chrono_duration.h"
472 
473 This type can represent 384,307,168 days (2^63 nanoseconds) forwards and
474 backwards in time in increments of 1 ns (1/1,000,000,000 of a second).
475 
476 Certain observations with respect to receiving durations in years and months
477 apply to both of these serializer decoders for `xsd:duration`.
478 
479 @see Section [time duration types](#toxsd8).
480 
481 Class/struct member additions {#typemap3}
482 -----------------------------
483 
484 All generated classes and structs can be augmented with additional
485 members such as methods, constructors and destructors, and private members:
486 
487  prefix__type = $ member-declaration
488 
489 For example, we can add method declarations and private members to a class, say
490 `ns__record` as follows:
491 
492  ns__record = $ ns__record(const ns__record &); // copy constructor
493  ns__record = $ void print(); // a print method
494  ns__record = $ private: int status; // a private member
495 
496 Note that method declarations cannot include any code, because soapcpp2's input
497 permits only type declarations, not code.
498 
499 Replacing XSD types by equivalent alternatives {#typemap4}
500 ----------------------------------------------
501 
502 Type replacements can be given to replace one type entirely with another given
503 type:
504 
505  prefix__type1 == prefix__type2
506 
507 This replaces all `prefix__type1` by `prefix__type2` in the wsdl2h output.
508 
509 @warning Do not agressively replace types, because this can cause XML
510 validation to fail when a value-type mismatch is encountered in the XML input.
511 Therefore, only replace similar types with other similar types that are wider
512 (e.g. `short` by `int` and `float` by `double`).
513 
514 The built-in typemap.dat variables $CONTAINER and $POINTER {#typemap5}
515 ----------------------------------------------------------
516 
517 The `typemap.dat` `$CONTAINER` variable defines the container to emit in the
518 generated declarations, which is `std::vector` by default. For example, to emit
519 `std::list` as the container in the wsdl2h-generated declarations:
520 
521  $CONTAINER = std::list
522 
523 The `typemap.dat` `$POINTER` variable defines the smart pointer to emit in the
524 generated declarations, which replaces the use of `*` pointers. For example:
525 
526  $POINTER = std::shared_ptr
527 
528 Not all pointers in the generated output can be replaced by smart pointers.
529 Regular pointers are still used as union members and for pointers to arrays of
530 objects.
531 
532 @note The standard smart pointer `std::shared_ptr` is generally safe to use.
533 Other smart pointers such as `std::unique_ptr` and `std::auto_ptr` may cause
534 compile-time errors when classes have smart pointer members but no copy
535 constructor (a default copy constructor). A copy constructor is required for
536 non-shared smart pointer copying or swapping.
537 
538 Alternatives to `std::shared_ptr` of the form `NAMESPACE::shared_ptr` can be
539 assigned to `$POINTER` when the namespace `NAMESPACE` also implements
540 `NAMESPACE::make_shared` and when the shared pointer class provides `reset()`
541 and`get()` methods and the dereference operator. For example Boost
542 `boost::shared_ptr`:
543 
544  [
545  #include <boost/shared_ptr.hpp>
546  ]
547  $POINTER = boost::shared_ptr
548 
549 The user-defined content between `[` and `]` ensures that we include the Boost
550 header files that are needed to support `boost::shared_ptr` and
551 `boost::make_shared`.
552 
553 User-defined content {#typemap6}
554 --------------------
555 
556 Any other content to be generated by wsdl2h can be included in `typemap.dat` by
557 enclosing it within brackets `[` and `]` anywhere in the `typemap.dat` file.
558 Each of the two brackets MUST appear at the start of a new line.
559 
560 For example, we can add an `#import "wsa5.h"` to the wsdl2h-generated output as
561 follows:
562 
563  [
564  #import "import/wsa5.h"
565  ]
566 
567 which emits the `#import "import/wsa5.h"` literally at the start of the
568 wsdl2h-generated header file.
569 
570 Mapping C/C++ to XML schema {#toxsd}
571 ===========================
572 
573 The soapcpp2 command generates the data binding implementation code from a data
574 binding interface `file.h`:
575 
576  soapcpp2 [options] file.h
577 
578 where `file.h` is a gSOAP header file that declares the XML data binding
579 interface. The `file.h` is typically generated by wsdl2h, but you can also
580 declare one yourself. If so, add `//gsaop` [directives](#directives) and
581 declare in this file all our C/C++ types you want to serialize in XML.
582 
583 You can also declare functions that will be converted to Web service operations
584 by soapcpp2. Global function declarations define service operations, which are
585 of the form:
586 
587 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
588  int prefix__func(arg1, arg2, ..., argn, result);
589 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
590 
591 where `arg1`, `arg2`, ..., `argn` are formal argument declarations of the input
592 and `result` is a formal argument for the output, which must be a pointer or
593 reference to the result object to be populated. More information can be found
594 in the [gSOAP user guide.](http://www.genivia.com/doc/soapdoc2.html)
595 
596 Overview of serializable C/C++ types {#toxsd1}
597 ------------------------------------
598 
599 The following C/C++ types are supported by soapcpp2 and mapped to XSD types
600 and constructs. See the subsections below for more details or follow the links.
601 
602 ### List of Boolean types
603 
604 | Boolean Type | Notes |
605 | ----------------------------- | ----------------------------------------------------------------------------------- |
606 | `bool` | C++ bool |
607 | `enum xsd__boolean` | C alternative to C++ `bool` with `false_` and `true_` |
608 
609 @see Section [C++ bool and C alternative](#toxsd3).
610 
611 ### List of enumeration and bitmask types
612 
613 | Enumeration Type | Notes |
614 | ----------------------------- | ----------------------------------------------------------------------------------- |
615 | `enum` | enumeration |
616 | `enum class` | C++11 scoped enumeration (soapcpp2 `-c++11`) |
617 | `enum*` | a bitmask that enumerates values 1, 2, 4, 8, ... |
618 | `enum* class` | C++11 scoped enumeration bitmask (soapcpp2 `-c++11`) |
619 
620 @see Section [enumerations and bitmasks](#toxsd4).
621 
622 ### List of numerical types
623 
624 | Numerical Type | Notes |
625 | ----------------------------- | ----------------------------------------------------------------------------------- |
626 | `char` | byte |
627 | `short` | 16 bit integer |
628 | `int` | 32 bit integer |
629 | `long` | 32 bit integer |
630 | `LONG64` | 64 bit integer |
631 | `xsd__integer` | 128 bit integer, use `#import "custom/int128.h"` |
632 | `long long` | same as `LONG64` |
633 | `unsigned char` | unsigned byte |
634 | `unsigned short` | unsigned 16 bit integer |
635 | `unsigned int` | unsigned 32 bit integer |
636 | `unsigned long` | unsigned 32 bit integer |
637 | `ULONG64` | unsigned 64 bit integer |
638 | `unsigned long long` | same as `ULONG64` |
639 | `int8_t` | same as `char` |
640 | `int16_t` | same as `short` |
641 | `int32_t` | same as `int` |
642 | `int64_t` | same as `LONG64` |
643 | `uint8_t` | same as `unsigned char` |
644 | `uint16_t` | same as `unsigned short` |
645 | `uint32_t` | same as `unsigned int` |
646 | `uint64_t` | same as `ULONG64` |
647 | `size_t` | transient type (not serializable) |
648 | `float` | 32 bit float |
649 | `double` | 64 bit float |
650 | `long double` | extended precision float, use `#import "custom/long_double.h"` |
651 | `xsd__decimal` | `<quadmath.h>` 128 bit quadruple precision float, use `#import "custom/float128.h"` |
652 | `typedef` | declares a type name, with optional value range and string length bounds |
653 
654 @see Section [numerical types](#toxsd5).
655 
656 ### List of string types
657 
658 | String Type | Notes |
659 | ----------------------------- | ----------------------------------------------------------------------------------- |
660 | `char*` | string (may contain UTF-8 with flag `SOAP_C_UTFSTRING`) |
661 | `wchar_t*` | wide string |
662 | `std::string` | C++ string (may contain UTF-8 with flag `SOAP_C_UTFSTRING`) |
663 | `std::wstring` | C++ wide string |
664 | `char[N]` | fixed-size string, requires soapcpp2 option `-b` |
665 | `_QName` | normalized QName content |
666 | `_XML` | literal XML string content with wide characters in UTF-8 |
667 | `typedef` | declares a new string type name, may restrict string length |
668 
669 @see Section [string types](#toxsd6).
670 
671 ### List of date and time types
672 
673 | Date and Time Type | Notes |
674 | --------------------------------------- | ------------------------------------------------------------------------- |
675 | `time_t` | date and time point since epoch |
676 | `struct tm` | date and time point, use `#import "custom/struct_tm.h"` |
677 | `struct tm` | date point, use `#import "custom/struct_tm_date.h"` |
678 | `struct timeval` | date and time point, use `#import "custom/struct_timeval.h"` |
679 | `unsigned long long` | time point in microseconds, use `#import "custom/long_time.h"` |
680 | `std::chrono::system_clock::time_point` | date and time point, use `#import "custom/chrono_time_point.h"` |
681 
682 @see Section [date and time types](#toxsd7).
683 
684 ### List of time duration types
685 
686 | Time Duration Type | Notes |
687 | ----------------------------- | ----------------------------------------------------------------------------------- |
688 | `long long` | duration in milliseconds, use `#import "custom/duration.h"` |
689 | `std::chrono::nanoseconds` | duration in nanoseconds, use `#import "custom/chrono_duration.h"` |
690 
691 @see Section [time duration types](#toxsd8).
692 
693 ### List of classes and structs
694 
695 | Classes, Structs, and Members | Notes |
696 | ----------------------------- | ----------------------------------------------------------------------------------- |
697 | `class` | C++ class with single inheritance only |
698 | `struct` | C struct or C++ struct without inheritance |
699 | `std::shared_ptr<T>` | C++11 smart shared pointer |
700 | `std::unique_ptr<T>` | C++11 smart pointer |
701 | `std::auto_ptr<T>` | C++ smart pointer |
702 | `std::deque<T>` | use `#import "import/stldeque.h"` |
703 | `std::list<T>` | use `#import "import/stllist.h"` |
704 | `std::vector<T>` | use `#import "import/stlvector.h"` |
705 | `std::set<T>` | use `#import "import/stlset.h"` |
706 | `template<T> class` | a container with `begin()`, `end()`, `size()`, `clear()`, and `insert()` methods |
707 | `T*` | data member: pointer to data of type `T` or points to array of `T` of size `__size` |
708 | `T[N]` | data member: fixed-size array of type `T` |
709 | `union` | data member: requires a variant selector member `__union` |
710 | `void*` | data member: requires a `__type` member to indicate the type of object pointed to |
711 
712 @see Section [classes and structs](#toxsd9).
713 
714 ### List of special classes and structs
715 
716 | Special Classes and Structs | Notes |
717 | ----------------------------- | ----------------------------------------------------------------------------------- |
718 | Special Array class/struct | single and multidimensional SOAP Arrays |
719 | Special Wrapper class/struct | complexTypes with simpleContent, wraps `__item` member |
720 | `xsd__hexBinary` | binary content |
721 | `xsd__base64Binary` | binary content and optional MIME/MTOM attachments |
722 | `xsd__anyType` | DOM elements, use `#import "dom.h"` |
723 | `@xsd__anyAttribute` | DOM attributes, use `#import "dom.h"` |
724 
725 @see Section [special classes and structs](#toxsd10).
726 
727 Colon notation versus name prefixing {#toxsd2}
728 ------------------------------------
729 
730 To bind C/C++ type names to XSD types, a simple form of name prefixing is used
731 by the gSOAP tools by prepending the XML namespace prefix to the C/C++ type
732 name with a pair of undescrores. This also ensures that name clashes cannot
733 occur when multiple WSDL and XSD files are converted to C/C++. Also, C++
734 namespaces are not sufficiently rich to capture XML schema namespaces
735 accurately, for example when class members are associated with schema elements
736 defined in another XML namespace and thus the XML namespace scope of the
737 member's name is relevant, not just its type.
738 
739 However, from a C/C++ centric point of view this can be cumbersome. Therefore,
740 colon notation is an alternative to physically augmenting C/C++ names with
741 prefixes.
742 
743 For example, the following class uses colon notation to bind the `record` class
744 to the `urn:types` schema:
745 
746 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
747  //gsoap ns schema namespace: urn:types
748  class ns:record // binding 'ns:' to a type name
749  {
750  public:
751  std::string name;
752  uint64_t SSN;
753  ns:record *spouse; // using 'ns:' with the type name
754  ns:record(); // using 'ns:' here too
755  ~ns:record(); // and here
756  };
757 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
758 
759 The colon notation is stripped away by soapcpp2 when generating the data
760 binding implementation code for our project. So the final code just uses
761 `record` to identify this class and its constructor/destructor.
762 
763 When using colon notation we have to be consistent and not use colon notation
764 mixed with prefixed forms. The name `ns:record` differs from `ns__record`,
765 because `ns:record` is compiled to an unqualified `record` name.
766 
767 Colon notation also facilitates overruling the elementFormDefault and
768 attributeFormDefault declaration that is applied to local elements and
769 attributes, when declared as members of classes, structs, and unions. For more
770 details, see [qualified and unqualified members](#toxsd9-6).
771 
772 C++ Bool and C alternatives {#toxsd3}
773 ---------------------------
774 
775 The C++ `bool` type is bound to built-in XSD type `xsd:boolean`.
776 
777 The C alternative is to define an enumeration:
778 
779 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
780  enum xsd__boolean { false_, true_ };
781 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
782 
783 or by defining an enumeration in C with pseudo-scoped enumeration constants:
784 
785 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
786  enum xsd__boolean { xsd__boolean__false, xsd__boolean__true };
787 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
788 
789 The XML value space of these types is `false` and `true`, but also accepted
790 are `0` and `1` values for false and true, respectively.
791 
792 To prevent name clashes, `false_` and `true_` have an underscore. Trailing
793 underscores are removed from the XML value space.
794 
795 Enumerations and bitmasks {#toxsd4}
796 -------------------------
797 
798 Enumerations are mapped to XSD simpleType enumeration restrictions of
799 `xsd:string`, `xsd:QName`, and `xsd:long`.
800 
801 Consider for example:
802 
803 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
804  enum ns__Color { RED, WHITE, BLUE };
805 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
806 
807 which maps to a simpleType restriction of `xsd:string` in the soapcpp2-generated
808 schema:
809 
810  <simpleType name="Color">
811  <restriction base="xsd:string">
812  <enumeration value="RED"/>
813  <enumeration value="WHITE"/>
814  <enumeration value="BLUE"/>
815  </restriction>
816  </simpleType>
817 
818 Enumeration name constants can be pseudo-scoped to prevent name clashes,
819 because enumeration name constants have a global scope in C and C++:
820 
821 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
822  enum ns__Color { ns__Color__RED, ns__Color__WHITE, ns__Color__BLUE };
823 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
824 
825 You can also use C++11 scoped enumerations to prevent name clashes:
826 
827 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
828  enum class ns__Color : int { RED, WHITE, BLUE };
829 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
830 
831 Here, the enumeration class base type `: int` is optional. In place of `int`
832 in the example above, we can also use `int8_t`, `int16_t`, `int32_t`, or
833 `int64_t`.
834 
835 The XML value space of the enumertions defined above is `RED`, `WHITE`, and
836 `BLUE`.
837 
838 Prefix-qualified enumeration name constants are mapped to simpleType
839 restrictions of `xsd:QName`, for example:
840 
841 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
842  enum ns__types { xsd__int, xsd__float };
843 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
844 
845 which maps to a simpleType restriction of `xsd:QName` in the soapcpp2-generated
846 schema:
847 
848  <simpleType name="types">
849  <restriction base="xsd:QName">
850  <enumeration value="xsd:int"/>
851  <enumeration value="xsd:float"/>
852  </restriction>
853  </simpleType>
854 
855 Enumeration name constants can be pseudo-numeric as follows:
856 
857 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
858  enum ns__Primes { _3 = 3, _5 = 5, _7 = 7, _11 = 11 };
859 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
860 
861 which maps to a simpleType restriction of `xsd:long`:
862 
863  <simpleType name="Color">
864  <restriction base="xsd:long">
865  <enumeration value="3"/>
866  <enumeration value="5"/>
867  <enumeration value="7"/>
868  <enumeration value="11"/>
869  </restriction>
870  </simpleType>
871 
872 The XML value space of this type is `3`, `5`, `7`, and `11`.
873 
874 Besides (pseudo-) scoped enumerations, another way to prevent name clashes
875 accross enumerations is to start an enumeration name constant with one
876 underscore or followed it by any number of underscores, which makes it
877 unique. The leading and trailing underscores are removed from the XML value
878 space.
879 
880 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
881  enum ns__ABC { A, B, C };
882  enum ns__BA { B, A }; // BAD: B = 1 but B is already defined as 2
883  enum ns__BA_ { B_, A_ }; // OK
884 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
885 
886 The gSOAP soapcpp2 tool permits reusing enumeration name constants across
887 (non-scoped) enumerations as long as these values are assigned the same
888 constant. Therefore, the following is permitted:
889 
890 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
891  enum ns__Primes { _3 = 3, _5 = 5, _7 = 7, _11 = 11 };
892  enum ns__Throws { _1 = 1, _2 = 2, _3 = 3, _4 = 4, _5 = 5, _6 = 6 };
893 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
894 
895 A bitmask type is an `enum*` "product" enumeration with a geometric,
896 power-of-two sequence of values assigned to the enumeration constants:
897 
898 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
899  enum* ns__Options { SSL3, TLS10, TLS11, TLS12 };
900 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
901 
902 where the product enum assigns 1 to `SSL3`, 2 to `TLS10`, 4 to `TLS11`, and 8
903 to `TLS12`, which allows these enumeration constants to be used in composing
904 bitmasks with `|` (bitwise or) `&` (bitwise and), and `~` (bitwise not):
905 
906 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
907  enum ns__Options options = (enum ns__Options)(SSL3 | TLS10 | TLS11 | TLS12);
908  if (options & SSL3) // if SSL3 is an option, warn and remove from options
909  {
910  warning();
911  options &= ~SSL3;
912  }
913 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
914 
915 The bitmask type maps to a simpleType list restriction of `xsd:string` in the
916 soapcpp2-generated schema:
917 
918  <simpleType name="Options">
919  <list>
920  <restriction base="xsd:string">
921  <enumeration value="SSL3"/>
922  <enumeration value="TLS10"/>
923  <enumeration value="TLS11"/>
924  <enumeration value="TLS12"/>
925  </restriction>
926  </list>
927  </simpleType>
928 
929 The XML value space of this type consists of all 16 possible subsets of the
930 four values, represented by an XML string with space-separated values. For
931 example, the bitmask `TLS10 | TLS11 | TLS12` equals 14 and is represented by
932 the XML string `TLS10 TLS11 TLS12`.
933 
934 You can also use C++11 scoped enumerations with bitmasks:
935 
936 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
937  enum* class ns__Options { SSL3, TLS10, TLS11, TLS12 };
938 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
939 
940 The base type of a scoped enumeration bitmask, when explicitly given, is
941 ignored. The base type is either `int` or `int64_t`, depending on the number
942 of constants enumerated in the bitmask.
943 
944 To convert `enum` name constants and bitmasks to a string, we use the
945 auto-generated function for enum `T`:
946 
947 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
948  const char *soap_T2s(struct soap*, enum T val)
949 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
950 
951 The string returned is stored in an internal buffer of the current `soap`
952 context, so you MUST copy it to keep it from being overwritten. For example,
953 use `char *soap_strdup(struct soap*, const char*)`.
954 
955 To convert a string to an `enum` constant or bitmask, we use the auto-generated
956 function
957 
958 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
959  int soap_s2T(struct soap*, const char *str, enum T *val)
960 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
961 
962 This function takes the name (or names, space-separated for bitmasks) of
963 the enumeration constant in a string `str`. Names should be given without the
964 pseudo-scope prefix and without trailing underscores. The function sets `val`
965 to the corresponding integer enum constant or to a bitmask. The function
966 returns `SOAP_OK` (zero) on success or an error if the string is not a valid
967 enumeration name.
968 
969 Numerical types {#toxsd5}
970 ---------------
971 
972 Integer and floating point types are mapped to the equivalent built-in XSD
973 types with the same sign and bit width.
974 
975 The `size_t` type is transient (not serializable) because its width is platform
976 dependent. We recommend to use `uint64_t` instead.
977 
978 The XML value space of integer types are their decimal representations without
979 loss of precision.
980 
981 The XML value space of floating point types are their decimal representations.
982 The decimal representations are formatted with the printf format string "%.9G"
983 for floats and the printf format string "%.17lG" for double. To change the
984 format strings, we can assign new strings to the following `struct soap`
985 context members:
986 
987 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
988  soap.float_format = "%g";
989  soap.double_format = "%lg";
990  soap.long_double_format = "%Lg";
991 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
992 
993 Note that decimal representations may result in a loss of precision of the
994 least significant decimal. Therefore, the format strings that are used by
995 default are sufficiently precise to avoid loss, but this may result in long
996 decimal fractions in the XML value space.
997 
998 The `long double` extended floating point type requires a custom serializer:
999 
1000 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
1001  #import "custom/long_double.h"
1002  ... use long double ...
1003 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1004 
1005 You can now use `long double`, which has a serializer that serializes this type
1006 as `xsd:decimal`. Compile and link your code with `custom/long_double.c`.
1007 
1008 The value space of floating point values includes the special values `INF`,
1009 `-INF`, and `NaN`. You can check a value for plus or minus infinity and
1010 not-a-number as follows:
1011 
1012 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
1013  soap_isinf(x) && x > 0 // is x INF?
1014  soap_isinf(x) && x < 0 // is x -INF?
1015  soap_isnan(x) // is x NaN?
1016 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1017 
1018 To assign these values, use:
1019 
1020 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
1021  // x is float // x is double, long double, or __float128
1022  x = FLT_PINFY; x = DBL_PINFTY;
1023  x = FLT_NINFY; x = DBL_NINFTY;
1024  x = FLT_NAN; x = DBL_NAN;
1025 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1026 
1027 If your system supports `__float128` then you can also use this 128 bit
1028 floating point type with a custom serializer:
1029 
1030 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
1031  #import "custom/float128.h"
1032  ... use xsd__decimal ...
1033 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1034 
1035 Then use the `xsd__decimal` alias of `__float128`, which has a serializer. Do
1036 not use `__float128` directly, which is transient (not serializable).
1037 
1038 To check for `INF`, `-INF`, and `NaN` of a `__float128` value use:
1039 
1040 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
1041  isinfq(x) && x > 0 // is x INF?
1042  isinfq(x) && x < 0 // is x -INF?
1043  isnanq(x) // is x NaN?
1044 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1045 
1046 The range of a typedef-defined numerical type can be restricted using the range
1047 `:` operator with inclusive lower and upper bounds. For example:
1048 
1049 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
1050  typedef int ns__narrow -10 : 10;
1051 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1052 
1053 This maps to a simpleType restriction of `xsd:int` in the soapcpp2-generated
1054 schema:
1055 
1056  <simpleType name="narrow">
1057  <restriction base="xsd:int">
1058  <minInclusive value="-10"/>
1059  <maxInclusive value="10"/>
1060  </restriction>
1061  </simpleType>
1062 
1063 The lower and upper bound of a range are optional. When omitted, values are
1064 not bound from below or from above, respectively.
1065 
1066 The range of a floating point typedef-defined type can be restricted within
1067 floating point constant bounds.
1068 
1069 Also with a floating point typedef a printf format pattern can be given of the
1070 form `"%[width][.precision]f"` to format decimal values using the given width
1071 and precision fields:
1072 
1073 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
1074  typedef float ns__PH "%5.2f" 0.0 : 14.0;
1075 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1076 
1077 This maps to a simpleType restriction of `xsd:float` in the soapcpp2-generated
1078 schema:
1079 
1080  <simpleType name="PH">
1081  <restriction base="xsd:float">
1082  <totalDigits value="5"/>
1083  <fractionDigits value="2"/>
1084  <minInclusive value="0"/>
1085  <maxInclusive value="14"/>
1086  </restriction>
1087  </simpleType>
1088 
1089 For exclusive bounds, we use the `<` operator instead of the `:` range
1090 operator:
1091 
1092 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
1093  typedef float ns__epsilon 0.0 < 1.0;
1094 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1095 
1096 Values `eps` of `ns__epsilon` are restricted between `0.0 < eps < 1.0`.
1097 
1098 This maps to a simpleType restriction of `xsd:float` in the soapcpp2-generated
1099 schema:
1100 
1101  <simpleType name="epsilon">
1102  <restriction base="xsd:float">
1103  <minExclusive value="0"/>
1104  <maxExclusive value="1"/>
1105  </restriction>
1106  </simpleType>
1107 
1108 To make just one of the bounds exclusive, while keeping the other bound
1109 inclusive, we add a `<` on the left or on the right side of the range ':'
1110 operator. For example:
1111 
1112 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
1113  typedef float ns__pos 0.0 < : ; // 0.0 < pos
1114  typedef float ns__neg : < 0.0 ; // neg < 0.0
1115 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1116 
1117 It is valid to make both left and right side exclusive with `< : <` which is in
1118 fact identical to the exlusive range `<` operator:
1119 
1120 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
1121  typedef float ns__epsilon 0.0 < : < 1.0; // 0.0 < eps < 1.0
1122 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1123 
1124 It helps to think of the `:` as a placeholder of the value between the two
1125 bounds, which is easier to memorize than the shorthand forms of bounds from
1126 which the `:` is removed:
1127 
1128 | Bounds | Validation Check | Shorthand |
1129 | ---------- | ---------------- | --------- |
1130 | 1 : | 1 <= x | 1 |
1131 | 1 : 10 | 1 <= x <= 10 | |
1132 | : 10 | x <= 10 | |
1133 | 1 < : < 10 | 1 < x < 10 | 1 < 10 |
1134 | 1 : < 10 | 1 <= x < 10 | |
1135 | : < 10 | x < 10 | < 10 |
1136 | 1 < : | 1 < x | 1 < |
1137 | 1 < : 10 | 1 < x <= 10 | |
1138 
1139 Besides `float`, also `double` and `long double` values can be restricted. For
1140 example, consider a nonzero probability extended floating point precision type:
1141 
1142 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
1143  #import "custom/long_double.h"
1144  typedef long double ns__probability "%16Lg" 0.0 < : 1.0;
1145 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1146 
1147 Value range restrictions are validated by the parser for all inbound XML data.
1148 A type fault `SOAP_TYPE` will be thrown by the deserializer if the value is out
1149 of range.
1150 
1151 Finally, if your system supports `__int128_t` then you can also use this 128
1152 bit integer type with a custom serializer:
1153 
1154 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
1155  #import "custom/int128.h"
1156  ... use xsd__integer ...
1157 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1158 
1159 Use the `xsd__integer` alias of `__int128_t`, which has a serializer. Do not
1160 use `__int128_t` directly, which is transient (not serializable).
1161 
1162 To convert numeric values to a string, we use the auto-generated function for
1163 numeric type `T`:
1164 
1165 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
1166  const char *soap_T2s(struct soap*, T val)
1167 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1168 
1169 For numeric types `T`, the string returned is stored in an internal buffer of
1170 the current `soap` context, so you MUST copy it to keep it from being
1171 overwritten. For example, use `char *soap_strdup(struct soap*, const char*)`.
1172 
1173 To convert a string to a numeric value, we use the auto-generated function
1174 
1175 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
1176  int soap_s2T(struct soap*, const char *str, T *val)
1177 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1178 
1179 where `T` is for example `int`, `LONG64`, `float`, `decimal` (the custom
1180 serializer name of `long double`) or `xsd__integer` (the custom serializer name
1181 of `__int128_t`). The function `soap_s2T` returns `SOAP_OK` on success or an
1182 error when the value is not numeric. For floating point types, "INF", "-INF"
1183 and "NaN" are valid strings to convert to numbers.
1184 
1185 String types {#toxsd6}
1186 ------------
1187 
1188 String types are mapped to the built-in `xsd:string` and `xsd:QName` XSD types.
1189 
1190 The wide strings `wchar_t*` and `std::wstring` may contain Unicode that is
1191 preserved in the XML value space.
1192 
1193 Strings `char*` and `std::string` can only contain extended Latin, but we can
1194 store UTF-8 content that is preserved in the XML value space when the `struct
1195 soap` context is initialized with the flag `XML_C_UTFSTRING`.
1196 
1197 @warning Beware that many XML 1.0 parsers reject all control characters (those
1198 between `#x1` and `#x1F`) except for `#x9`, `#xA`, and `#xD`. With the
1199 newer XML 1.1 version parsers (including gSOAP) you should be fine.
1200 
1201 The length of a string of a typedef-defined string type can be restricted:
1202 
1203 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
1204  typedef std::string ns__password 6 : 16;
1205 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1206 
1207 which maps to a simpleType restriction of `xsd:string` in the soapcpp2-generated
1208 schema:
1209 
1210  <simpleType name="password">
1211  <restriction base="xsd:string">
1212  <minLength value="6"/>
1213  <maxLength value="16"/>
1214  </restriction>
1215  </simpleType>
1216 
1217 String length restrictions are validated by the parser for inbound XML data.
1218 A value length fault `SOAP_LENGTH` will be thrown by the deserializer if the
1219 string is too long or too short.
1220 
1221 In addition, an XSD regex pattern restriction can be associated with a string
1222 typedef:
1223 
1224 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
1225  typedef std::string ns__password "([a-zA-Z]|[0-9]|-)+" 6 : 16;
1226 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1227 
1228 which maps to a simpleType restriction of `xsd:string` in the soapcpp2-generated
1229 schema:
1230 
1231  <simpleType name="password">
1232  <restriction base="xsd:string">
1233  <pattern value="([a-zA-Z0-9]|-)+"/>
1234  <minLength value="6"/>
1235  <maxLength value="16"/>
1236  </restriction>
1237  </simpleType>
1238 
1239 Pattern restrictions are validated by the parser for inbound XML data only if
1240 the `soap::fsvalidate` and `soap::fwvalidate` callbacks are defined, see the
1241 [gSOAP user guide.](http://www.genivia.com/doc/soapdoc2.html)
1242 
1243 Exclusive length bounds can be used with strings:
1244 
1245 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
1246  typedef std::string ns__string255 : < 256; // same as 0 : 255
1247 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1248 
1249 Fixed-size strings (`char[N]`) are rare occurrences in the wild, but apparently
1250 still used in some projects to store strings. To facilitate fixed-size string
1251 serialization, use soapcpp2 option `-b`. For example:
1252 
1253 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
1254  typedef char ns__buffer[10]; // requires soapcpp2 option -b
1255 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1256 
1257 which maps to a simpleType restriction of `xsd:string` in the soapcpp2-generated
1258 schema:
1259 
1260  <simpleType name="buffer">
1261  <restriction base="xsd:string">
1262  <maxLength value="9"/>
1263  </restriction>
1264  </simpleType>
1265 
1266 Note that fixed-size strings MUST contain NUL-terminated text and SHOULD NOT
1267 contain raw binary data. Also, the length limitation is more restrictive for
1268 UTF-8 content (enabled with the `SOAP_C_UTFSTRING`) that requires multibyte
1269 character encodings. As a consequence, UTF-8 content may be truncated to fit.
1270 
1271 Note that raw binary data can be stored in a `xsd__base64Binary` or
1272 `xsd__hexBinary` structure, or transmitted as a MIME attachment.
1273 
1274 The built-in `_QName` type is a regular C string type (`char*`) that maps to
1275 `xsd:QName` but has the added advantage that it holds normalized qualified names.
1276 There are actually two forms of normalized QName content, to ensure any QName
1277 is represented accurately and uniquely:
1278 
1279 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
1280  "prefix:name"
1281  "\"URI\":name"
1282 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1283 
1284 The first form of string is used when the prefix (and the binding URI) is
1285 defined in the namespace table and is bound to a URI (see the .nsmap file).
1286 The second form is used when the URI is not defined in the namespace table and
1287 therefore no prefix is available to bind and normalize the URI to.
1288 
1289 A `_QName` string may contain a sequence of space-separated QName values, not
1290 just one, and all QName values are normalized to the format shown above.
1291 
1292 To define a `std::string` base type for `xsd:QName`, we use a typedef:
1293 
1294 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
1295  typedef std::string xsd__QName;
1296 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1297 
1298 The `xsd__QName` string content is normalized, just as with the `_QName`
1299 normalization.
1300 
1301 To serialize strings that contain literal XML content to be reproduced in the
1302 XML value space, use the built-in `_XML` string type, which is a regular C
1303 string type (`char*`) that maps to plain XML CDATA.
1304 
1305 To define a `std::string` base type for literal XML content, use a typedef:
1306 
1307 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
1308  typedef std::string XML;
1309 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1310 
1311 Strings can hold any of the values of the XSD built-in primitive types. We can
1312 use a string typedef to declare the use of the string type as a XSD built-in
1313 type:
1314 
1315 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
1316  typedef std::string xsd__token;
1317 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1318 
1319 You MUST ensure that the string values we populate in this type conform to the
1320 XML standard, which in case of `xsd:token` is the lexical and value spaces of
1321 `xsd:token` are the sets of all strings after whitespace replacement of any
1322 occurrence of `#x9`, `#xA` , and `#xD` by `#x20` and collapsing.
1323 
1324 To copy `char*` or `wchar_t*` strings with a context that manages the allocated
1325 memory, use functions
1326 
1327 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
1328  char *soap_strdup(struct soap*, const char*)
1329  wchar_t *soap_wstrdup(struct soap*, const wchar_t*)
1330 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1331 
1332 To convert a wide string to a UTF-8 encoded string, use function
1333 
1334 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
1335  const char* SOAP_FMAC2 soap_wchar2s(struct soap*, const wchar_t *s)
1336 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1337 
1338 The function allocates and returns a string, with its memory being managed by
1339 the context.
1340 
1341 To convert a UTF-8 encoded string to a wide string, use function
1342 
1343 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
1344  int soap_s2wchar(struct soap*, const char *from, wchar_t **to, long minlen, long maxlen)
1345 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1346 
1347 where `to` is set to point to an allocated `wchar_t*` string. Pass `-1` for
1348 `minlen` and `maxlen` to ignore length constraints on the target string. The
1349 function returns `SOAP_OK` or an error when the length constraints are not met.
1350 
1351 Date and time types {#toxsd7}
1352 -------------------
1353 
1354 The C/C++ `time_t` type is mapped to the built-in `xsd:dateTime` XSD type that
1355 represents a date and time within a time zone (typically UTC).
1356 
1357 The XML value space contains ISO 8601 Gregorian time instances of the form
1358 `[-]CCYY-MM-DDThh:mm:ss.sss[Z|(+|-)hh:mm]`, where `Z` is the UTC time zone
1359 or a time zone offset `(+|-)hh:mm]` from UTC is used.
1360 
1361 A `time_t` value is considered and represented in UTC by the serializer.
1362 
1363 Because the `time_t` value range is restricted to dates after 01/01/1970 and
1364 before 2038 assuming `time_t` is a `long` 32 bit, care must be taken to ensure
1365 the range of `xsd:dateTime` values in XML exchanges do not exceed the `time_t`
1366 range.
1367 
1368 This restriction does not hold for `struct tm` (`<time.h>`), which we can use
1369 to store and exchange a date and time in UTC without date range restrictions.
1370 The serializer uses the `struct tm` members directly for the XML value space of
1371 `xsd:dateTime`:
1372 
1373 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
1374  struct tm
1375  {
1376  int tm_sec; // seconds (0 - 60)
1377  int tm_min; // minutes (0 - 59)
1378  int tm_hour; // hours (0 - 23)
1379  int tm_mday; // day of month (1 - 31)
1380  int tm_mon; // month of year (0 - 11)
1381  int tm_year; // year - 1900
1382  int tm_wday; // day of week (Sunday = 0) (NOT USED)
1383  int tm_yday; // day of year (0 - 365) (NOT USED)
1384  int tm_isdst; // is summer time in effect?
1385  char* tm_zone; // abbreviation of timezone (NOT USED)
1386  };
1387 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1388 
1389 You will lose the day of the week information. It is always Sunday
1390 (`tm_wday=0`) and the day of the year is not set either. The time zone is UTC.
1391 
1392 This `struct tm` type is mapped to the built-in `xsd:dateTime` XSD type and
1393 serialized with the custom serializer `custom/struct_tm.h` that declares a
1394 `xsd__dateTime` type:
1395 
1396 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
1397  #import "custom/struct_tm.h" // import typedef struct tm xsd__dateTime;
1398  ... use xsd__dateTime ...
1399 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1400 
1401 Compile and link your code with `custom/struct_tm.c`.
1402 
1403 The `struct timeval` (`<sys/time.h>`) type is mapped to the built-in
1404 `xsd:dateTime` XSD type and serialized with the custom serializer
1405 `custom/struct_timeval.h` that declares a `xsd__dateTime` type:
1406 
1407 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
1408  #import "custom/struct_timeval.h" // import typedef struct timeval xsd__dateTime;
1409  ... use xsd__dateTime ...
1410 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1411 
1412 Compile and link your code with `custom/struct_timeval.c`.
1413 
1414 Note that the same value range restrictions apply to `struct timeval` as they
1415 apply to `time_t`. The added benefit of `struct timeval` is the addition of
1416 a microsecond-precise clock:
1417 
1418 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
1419  struct timeval
1420  {
1421  time_t tv_sec; // seconds since Jan. 1, 1970
1422  suseconds_t tv_usec; // and microseconds
1423  };
1424 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1425 
1426 A C++11 `std::chrono::system_clock::time_point` type is mapped to the built-in
1427 `xsd:dateTime` XSD type and serialized with the custom serializer
1428 `custom/chrono_time_point.h` that declares a `xsd__dateTime` type:
1429 
1430 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
1431  #import "custom/chrono_time_point.h" // import typedef std::chrono::system_clock::time_point xsd__dateTime;
1432  ... use xsd__dateTime ...
1433 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1434 
1435 Compile and link your code with `custom/chrono_time_point.cpp`.
1436 
1437 The `struct tm` type is mapped to the built-in `xsd:date` XSD type and serialized
1438 with the custom serializer `custom/struct_tm_date.h` that declares a
1439 `xsd__date` type:
1440 
1441 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
1442  #import "custom/struct_tm_date.h" // import typedef struct tm xsd__date;
1443  ... use xsd__date ...
1444 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1445 
1446 Compile and link your code with `custom/struct_tm_date.c`.
1447 
1448 The XML value space of `xsd:date` are Gregorian calendar dates of the form
1449 `[-]CCYY-MM-DD[Z|(+|-)hh:mm]` with a time zone.
1450 
1451 The serializer ignores the time part and the deserializer only populates the
1452 date part of the struct, setting the time to 00:00:00. There is no unreasonable
1453 limit on the date range because the year field is stored as an integer (`int`).
1454 
1455 An `unsigned long long` (`ULONG64` or `uint64_t`) type that contains a 24 hour
1456 time in microseconds UTC is mapped to the built-in `xsd:time` XSD type and
1457 serialized with the custom serializer `custom/long_time.h` that declares a
1458 `xsd__time` type:
1459 
1460 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
1461  #import "custom/long_time.h" // import typedef unsigned long long xsd__time;
1462  ... use xsd__time ...
1463 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1464 
1465 Compile and link your code with `custom/long_time.c`.
1466 
1467 This type represents `00:00:00.000000` to `23:59:59.999999`, from 0 to an
1468 upper bound of 86,399,999,999. A microsecond resolution means that a 1 second
1469 increment requires an increment of 1,000,000 in the integer value.
1470 
1471 The XML value space of `xsd:time` are points in time recurring each day of the
1472 form `hh:mm:ss.sss[Z|(+|-)hh:mm]`, where `Z` is the UTC time zone or a time
1473 zone offset from UTC is used. The `xsd__time` value is always considered and
1474 represented in UTC by the serializer.
1475 
1476 To convert date and/or time values to a string, we use the auto-generated
1477 function for type `T`:
1478 
1479 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
1480  const char *soap_T2s(struct soap*, T val)
1481 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1482 
1483 For date and time types `T`, the string returned is stored in an internal
1484 buffer of the current `soap` context, so you MUST copy it to keep it from being
1485 overwritten. For example, use `char *soap_strdup(struct soap*, const char*)`.
1486 
1487 To convert a string to a date/time value, we use the auto-generated function
1488 
1489 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
1490  int soap_s2T(struct soap*, const char *str, T *val)
1491 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1492 
1493 where `T` is for example `dateTime` (for `time_t`), `xsd__dateTime` (for
1494 `struct tm`, `struct timeval`, or `std::chrono::system_clock::time_point`).
1495 The function `soap_s2T` returns `SOAP_OK` on success or an error when the value
1496 is not a date/time.
1497 
1498 Time duration types {#toxsd8}
1499 -------------------
1500 
1501 The XML value space of `xsd:duration` are values of the form `PnYnMnDTnHnMnS`
1502 where the capital letters are delimiters. Delimiters may be omitted when the
1503 corresponding member is not used.
1504 
1505 A `long long` (`LONG64` or `int64_t`) type that contains a duration (time
1506 lapse) in milliseconds is mapped to the built-in `xsd:duration` XSD type and
1507 serialized with the custom serializer `custom/duration.h` that declares a
1508 `xsd__duration` type:
1509 
1510 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
1511  #import "custom/duration.h" // import typedef long long xsd__duration;
1512  ... use xsd__duration ...
1513 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1514 
1515 Compile and link your code with `custom/duration.c`.
1516 
1517 The duration type `xsd__duration` can represent 106,751,991,167 days forward
1518 and backward with millisecond precision.
1519 
1520 Durations that exceed a month are always output in days, rather than months to
1521 avoid days-per-month conversion inacurracies.
1522 
1523 Durations that are received in years and months instead of total number of days
1524 from a reference point are not well defined, since there is no accepted
1525 reference time point (it may or may not be the current time). The decoder
1526 simple assumes that there are 30 days per month. For example, conversion of
1527 "P4M" gives 120 days. Therefore, the durations "P4M" and "P120D" are assumed
1528 to be identical, which is not necessarily true depending on the reference point
1529 in time.
1530 
1531 Rescaling of the duration value by may be needed when adding the duration value
1532 to a `time_t` value, because `time_t` may or may not have a seconds resolution,
1533 depending on the platform and possible changes to `time_t`.
1534 
1535 Rescaling is done automatically when you add a C++11 `std::chrono::nanoseconds`
1536 value to a `std::chrono::system_clock::time_point` value. To use
1537 `std::chrono::nanoseconds` as `xsd:duration`:
1538 
1539 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
1540  #import "custom/chrono_duration.h" // import typedef std::chrono::duration xsd__duration;
1541  ... use xsd__duration ...
1542 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1543 
1544 Compile and link your code with `custom/chrono_duration.cpp`.
1545 
1546 This type can represent 384,307,168 days (2^63 nanoseconds) forwards and
1547 backwards in time in increments of 1 ns (1/1000000000 second).
1548 
1549 The same observations with respect to receiving durations in years and months
1550 apply to this serializer's decoder.
1551 
1552 To convert duration values to a string, we use the auto-generated function
1553 
1554 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
1555  const char *soap_xsd__duration2s(struct soap*, xsd__duration val)
1556 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1557 
1558 The string returned is stored in an internal buffer, so you MUST copy it to
1559 keep it from being overwritten, Use `soap_strdup(struct soap*, const char*)`
1560 for example to copy this string.
1561 
1562 To convert a string to a duration value, we use the auto-generated function
1563 
1564 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
1565  int soap_s2xsd__dateTime(struct soap*, const char *str, xsd__dateTime *val)
1566 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1567 
1568 The function returns `SOAP_OK` on success or an error when the value is not a
1569 duration.
1570 
1571 Classes and structs {#toxsd9}
1572 -------------------
1573 
1574 Classes and structs are mapped to XSD complexTypes. The XML value space
1575 consists of XML elements with attributes and subelements, possibly constrained
1576 by validation rules that enforce element and attribute occurrence contraints,
1577 numerical value range constraints, and string length and pattern constraints.
1578 
1579 Classes that are declared with the gSOAP tools are limited to single
1580 inheritence only. Structs cannot be inherited.
1581 
1582 The class and struct name is bound to an XML namespace by means of the prefix
1583 naming convention or by using [colon notation](#toxsd1):
1584 
1585 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
1586  //gsoap ns schema namespace: urn:types
1587  class ns__record
1588  {
1589  public:
1590  std::string name;
1591  uint64_t SSN;
1592  ns__record *spouse;
1593  ns__record();
1594  ~ns__record();
1595  protected:
1596  struct soap *soap;
1597  };
1598 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1599 
1600 In the example above, we also added a context pointer to the `struct soap` that
1601 manages this instance. It is set when the instance is created in the engine's
1602 context, for example when deserialized and populated by the engine.
1603 
1604 The class maps to a complexType in the soapcpp2-generated schema:
1605 
1606  <complexType name="record">
1607  <sequence>
1608  <element name="name" type="xsd:string" minOccurs="1" maxOccurs="1"/>
1609  <element name="SSN" type="xsd:unsignedLong" minOccurs="1" maxOccurs="1"/>
1610  <element name="spouse" type="ns:record" minOccurs="0" maxOccurs="1" nillable="true"/>
1611  </sequence>
1612  </complexType>
1613 
1614 ### Serializable versus transient types and members {#toxsd9-1}
1615 
1616 Public data members of a class or struct are serialized. Private and protected
1617 members are transient and not serializable.
1618 
1619 Also `const` and `static` members are not serializable, with the exception of
1620 `const char*` and `const wchar_t*`. Types and specific class/struct members
1621 can also be made transient with the `extern` qualifier:
1622 
1623 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
1624  extern class std::ostream; // declare 'std::ostream' transient
1625  class ns__record
1626  {
1627  public:
1628  extern int num; // not serialized
1629  std::ostream out; // not serialized
1630  static const int MAX = 1024; // not serialized
1631  };
1632 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1633 
1634 By declaring `std::ostream` transient with `extern` you can use this type
1635 wherever you need it without soapcpp2 complaining that this class is not
1636 defined.
1637 
1638 ### Volatile classes and structs {#toxsd9-2}
1639 
1640 Classes and structs can be declared `volatile` with the gSOAP tools. This means
1641 that they are already declared elsewhere in your project's source code and you
1642 do not want soapcpp2 to generate code with a second declaration of these types.
1643 
1644 For example, `struct tm` is declared in `<time.h>`. You can make it serializable
1645 and include a partial list of data members that you want to serialize:
1646 
1647 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
1648  volatile struct tm
1649  {
1650  int tm_sec; // seconds (0 - 60)
1651  int tm_min; // minutes (0 - 59)
1652  int tm_hour; // hours (0 - 23)
1653  int tm_mday; // day of month (1 - 31)
1654  int tm_mon; // month of year (0 - 11)
1655  int tm_year; // year - 1900
1656  };
1657 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1658 
1659 You can declare classes and structs `volatile` for any such types you want to
1660 serialize by only providing the public data members you want to serialize.
1661 
1662 In addition, [colon notation](#toxsd2) is a simple and effective way to bind an
1663 existing class or struct to a schema. For example, you can change the `tm` name
1664 as follows without affecting the code that uses `struct tm` generated by
1665 soapcpp2:
1666 
1667 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
1668  volatile struct ns:tm { ... }
1669 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1670 
1671 This struct maps to a complexType in the soapcpp2-generated schema:
1672 
1673  <complexType name="tm">
1674  <sequence>
1675  <element name="tm-sec" type="xsd:int" minOccurs="1" maxOccurs="1"/>
1676  <element name="tm-min" type="xsd:int" minOccurs="1" maxOccurs="1"/>
1677  <element name="tm-hour" type="xsd:int" minOccurs="1" maxOccurs="1"/>
1678  <element name="tm-mday" type="xsd:int" minOccurs="1" maxOccurs="1"/>
1679  <element name="tm-mon" type="xsd:int" minOccurs="1" maxOccurs="1"/>
1680  <element name="tm-year" type="xsd:int" minOccurs="1" maxOccurs="1"/>
1681  </sequence>
1682  </complexType>
1683 
1684 ### Mutable classes and structs {#toxsd9-3}
1685 
1686 Classes and structs can be declared `mutable` with the gSOAP tools. This means
1687 that their definition can be spread out over the source code. This promotes the
1688 concept of a class or struct as a *row of named values*, also known as a *named
1689 tuple*, that can be extended at compile time in your source code with additional
1690 members. Because these types differ from the traditional object-oriented
1691 principles and design concepts of classes and objects, constructors and
1692 destructors cannot be defined (also because we cannot guarantee merging these
1693 into one such that all members will be initialized). A default constructor,
1694 copy constructor, assignment operation, and destructor will be assigned
1695 automatically by soapcpp2.
1696 
1697 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
1698  mutable struct ns__tuple
1699  {
1700  @std::string id;
1701  };
1702 
1703  mutable struct ns__tuple
1704  {
1705  std::string name;
1706  std::string value;
1707  };
1708 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1709 
1710 The members are collected into one definition generated by soapcpp2. Members
1711 may be repeated from one definition to another, but only if their associated
1712 types are identical. So, for example, a third extension with a `value` member
1713 with a different type fails:
1714 
1715 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
1716  mutable struct ns__tuple
1717  {
1718  float value; // BAD: value is already declared std::string
1719  };
1720 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1721 
1722 The `mutable` concept has proven to be very useful when declaring and
1723 collecting SOAP Headers for multiple services, which are collected into one
1724 `struct SOAP_ENV__Header` by the soapcpp2 tool.
1725 
1726 ### Default member values in C and C++ {#toxsd9-4}
1727 
1728 Class and struct data members in C and C++ may be declared with an optional
1729 default initialization value that is provided "inline" with the declaration of
1730 the member:
1731 
1732 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
1733  class ns__record
1734  {
1735  public:
1736  std::string name = "Joe";
1737  ...
1738  };
1739 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1740 
1741 These initializations are made by the default constructor that is added by
1742 soapcpp2 to each class and struct. A constructor is only added when a default
1743 constructor is not already defined with the class declaration. You can
1744 explicitly (re)initialize an object with these initial values by using the
1745 soapcpp2 auto-generated functions:
1746 
1747 - `void T::soap_default(struct soap*)` for `class T` (C++ only)
1748 - `void soap_default_T(struct soap*, T*)` for `struct T` (C and C++).
1749 
1750 Initializations can only be provided for members that have primitive types
1751 (`bool`, `enum`, `time_t`, numeric and string types).
1752 
1753 @see Section [operations on classes and structs](#toxsd9-13).
1754 
1755 ### Attribute members {#toxsd9-5}
1756 
1757 Class and struct data members can be declared as XML attributes by annotating
1758 their type with a `@` with the declaration of the member:
1759 
1760 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
1761  class ns__record
1762  {
1763  public:
1764  @std::string name;
1765  @uint64_t SSN;
1766  ns__record *spouse;
1767  };
1768 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1769 
1770 This class maps to a complexType in the soapcpp2-generated schema:
1771 
1772  <complexType name="record">
1773  <sequence>
1774  <element name="spouse" type="ns:record" minOccurs="0" maxOccurs="1" nillable="true"/>
1775  </sequence>
1776  <attribute name="name" type="xsd:string" use="required"/>
1777  <attribute name="SSN" type="xsd:unsignedLong" use="required"/>
1778  </complexType>
1779 
1780 An example XML instance of `ns__record` is:
1781 
1782  <ns:record xmlns:ns="urn:types" name="Joe" SSN="1234567890">
1783  <spouse name="Jane" SSN="1987654320">
1784  </spouse>
1785  </ns:record>
1786 
1787 Attribute data members are restricted to primitive types (`bool`, `enum`,
1788 `time_t`, numeric and string types), `xsd__hexBinary`, `xsd__base64Binary`, and
1789 custom serializers, such as `xsd__dateTime`. Custom serializers for types that
1790 may be used as attributes MUST define `soap_s2T` and `soap_T2s` functions that
1791 convert values of type `T` to strings and back.
1792 
1793 Attribute data members can be pointers and smart pointers to these types, which
1794 permits attributes to be optional.
1795 
1796 ### Qualified and unqualified members {#toxsd9-6}
1797 
1798 Class, struct, and union data members are mapped to namespace qualified or
1799 unqualified tag names of local elements and attributes. If a data member has
1800 no prefix then the default form of qualification is applied based on the
1801 element/attribute form that is declared with the schema of the class, struct,
1802 or union type. If the member name has a namespace prefix by colon notation,
1803 then the prefix overrules the default (un)qualified form. Therefore,
1804 [Colon notation](toxsd2) is an effective mechanism to control qualification of
1805 tag names of individual members of classes, structs, and unions.
1806 
1807 The XML schema elementFormDefault and attributeFormDefault declarations control
1808 the tag name qualification of local elements and attributes, respectively.
1809 
1810 - "unqualified" indicates that local elements/attributes are not qualified with
1811  the namespace prefix.
1812 
1813 - "qualified" indicates that local elements/attributes must be qualified with
1814  the namespace prefix.
1815 
1816 Individual schema declarations of local elements and attributes may overrule
1817 this by using the form declaration in a schema and by using colon notation to
1818 add namespace prefixes to class, struct, and union members in the header file
1819 for soapcpp2.
1820 
1821 Consider for example an `ns__record` class in the `ns` namespace in which local
1822 elements are qualified and local attributes are unqualified by default:
1823 
1824 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
1825  //gsoap ns schema namespace: urn:types
1826  //gsoap ns schema elementForm: qualified
1827  //gsoap ns schema attributeForm: unqualified
1828  class ns__record
1829  {
1830  public:
1831  @std::string name;
1832  @uint64_t SSN;
1833  ns__record *spouse;
1834  };
1835 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1836 
1837 This class maps to a complexType in the soapcpp2-generated schema with
1838 targetNamespace "urn:types", elementFormDefault qualified and
1839 attributeFormDefault unqualified:
1840 
1841  <schema targetNamespace="urn:types"
1842  ...
1843  elementFormDefault="qualified"
1844  attributeFormDefault="unqualified"
1845  ... >
1846  <complexType name="record">
1847  <sequence>
1848  <element name="spouse" type="ns:record" minOccurs="0" maxOccurs="1" nillable="true"/>
1849  </sequence>
1850  <attribute name="name" type="xsd:string" use="required"/>
1851  <attribute name="SSN" type="xsd:unsignedLong" use="required"/>
1852  </complexType>
1853  </schema>
1854 
1855 An example XML instance of `ns__record` is:
1856 
1857  <ns:record xmlns:ns="urn:types" name="Joe" SSN="1234567890">
1858  <ns:spouse> name="Jane" SSN="1987654320">
1859  </ns:spouse>
1860  </ns:record>
1861 
1862 Note that the root element ns:record is qualified because it is a root element
1863 of the schema with target namespace "urn:types". Its local element ns:spouse
1864 is namespace qualified because the elementFormDefault of local elements is
1865 qualified. Attributes are unqualified.
1866 
1867 The default namespace (un)qualification of local elements and attributes can be
1868 overruled by adding a prefix to the member name by using colon notation:
1869 
1870 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
1871  //gsoap ns schema namespace: urn:types
1872  //gsoap ns schema elementForm: qualified
1873  //gsoap ns schema attributeForm: unqualified
1874  class ns__record
1875  {
1876  public:
1877  @std::string ns:name; // 'ns:' qualified
1878  @uint64_t SSN;
1879  ns__record *:spouse; // ':' unqualified (empty prefix)
1880  };
1881 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1882 
1883 The colon notation for member `ns:name` forces qualification of its attribute
1884 tag in XML. The colon notation for member `:spouse` removes qualification from
1885 its local element tag:
1886 
1887  <schema targetNamespace="urn:types"
1888  ...
1889  elementFormDefault="unqualified"
1890  attributeFormDefault="unqualified"
1891  ... >
1892  <complexType name="record">
1893  <sequence>
1894  <element name="spouse" type="ns:record" minOccurs="0" maxOccurs="1" nillable="true" form="unqualified"/>
1895  </sequence>
1896  <attribute name="name" type="xsd:string" use="required" form="qualified"/>
1897  <attribute name="SSN" type="xsd:unsignedLong" use="required"/>
1898  </complexType>
1899  </schema>
1900 
1901 XML instances of `ns__record` have unqualified spouse elements and qualified
1902 ns:name attributes:
1903 
1904  <ns:record xmlns:ns="urn:types" ns:name="Joe" SSN="1234567890">
1905  <spouse> ns:name="Jane" SSN="1987654320">
1906  </spouse>
1907  </ns:record>
1908 
1909 Note that data members can also be prefixed using the `prefix__name`
1910 convention. However, this has a different effect by referring to global (root)
1911 elements and attributes, see [defining document root elements](#toxsd9-7).
1912 
1913 @note You must declare a target namespace with a `//gsoap ns schema namespace:`
1914 directive to enable the `elementForm` and `attributeForm` directives in order
1915 to generate valid schemas with soapcpp2. See [directives](#directives) for
1916 more details.
1917 
1918 ### Defining document root elements {#toxsd9-7}
1919 
1920 To define and reference XML document root elements we use type names that start
1921 with an underscore:
1922 
1923 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
1924  class _ns__record
1925 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1926 
1927 Alternatively, we can use a typedef to define a document root element with a
1928 given type:
1929 
1930 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
1931  typedef ns__record _ns__record;
1932 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1933 
1934 This typedef maps to a global root element that is added to the
1935 soapcpp2-generated schema:
1936 
1937  <element name="record" type="ns:record"/>
1938 
1939 An example XML instance of `_ns__record` is:
1940 
1941  <ns:record xmlns:ns="urn:types">
1942  <name>Joe</name>
1943  <SSN>1234567890</SSN>
1944  <spouse>
1945  <name>Jane</name>
1946  <SSN>1987654320</SSN>
1947  </spouse>
1948  </ns:record>
1949 
1950 Global-level element/attribute definitions are also referenced and/or added to
1951 the generated schema when serializable data members reference these by their
1952 qualified name:
1953 
1954 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
1955  typedef std::string _ns__name 1 : 100;
1956  class _ns__record
1957  {
1958  public:
1959  @_QName xsi__type; // built-in XSD attribute xsi:type
1960  _ns__name ns__name; // ref to global ns:name element
1961  uint64_t SSN;
1962  _ns__record *spouse;
1963  };
1964 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1965 
1966 These types map to the following comonents in the soapcpp2-generated schema:
1967 
1968  <simpleType name="name">
1969  <restriction base="xsd:string">
1970  <minLength value="1"/>
1971  <maxLength value="100"/>
1972  </restriction>
1973  </simpleType>
1974  <element name="name" type="ns:name"/>
1975  <complexType name="record">
1976  <sequence>
1977  <element ref="ns:name" minOccurs="1" maxOccurs="1"/>
1978  <element name="SSN" type="xsd:unsignedLong" minOccurs="1" maxOccurs="1"/>
1979  <element name="spouse" type="ns:record" minOccurs="0" maxOccurs="1" nillable="true"/>
1980  </sequence>
1981  <attribute ref="xsi:type" use="optional"/>
1982  </complexType>
1983  <element name="record" type="ns:record"/>
1984 
1985 Use only use qualified member names when their types match the global-level
1986 element types that they refer to. For example:
1987 
1988 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
1989  typedef std::string _ns__name; // global element ns:name of type xsd:string
1990  class _ns__record
1991  {
1992  public:
1993  int ns__name; // BAD: global element ns:name is NOT type int
1994  _ns__record ns__record; // OK: ns:record is a global-level root element
1995  ...
1996  };
1997 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1998 
1999 Therefore, we recommend to use qualified member names only when necessary to
2000 refer to standard XSD elements and attributes, such as `xsi__type`, and
2001 `xsd__lang`.
2002 
2003 By contrast, colon notation has the desired effect to (un)qualify local tag
2004 names by overruling the default element/attribute namespace qualification, see
2005 [qualified and unqualified members](#toxsd9-6).
2006 
2007 ### (Smart) pointer members and their occurrence constraints {#toxsd9-8}
2008 
2009 A public pointer-typed data member is serialized by following its (smart)
2010 pointer(s) to the value pointed to. To serialize pointers to dynamic arrays of
2011 data, please see the next section on [container members and their occurrence
2012 constraints](#toxsd9-9).
2013 
2014 Pointers that are NULL and smart pointers that are empty are serialized to
2015 produce omitted element and attribute values, unless an element is required
2016 and is nillable.
2017 
2018 To control the occurrence requirements of pointer-based data members,
2019 occurrence constraints are associated with data members in the form of a range
2020 `minOccurs : maxOccurs`. For non-repeatable (meaning, not a container or array)
2021 data members, there are only three reasonable occurrence constraints:
2022 
2023 - `0:0` means that this element or attribute is prohibited.
2024 - `0:1` means that this element or attribute is optional.
2025 - `1:1` means that this element or attribute is required.
2026 
2027 Pointer-based data members have a default `0:1` occurrence constraint, making
2028 them optional, and their XML schema local element/attribute definition is
2029 marked as nillable. Non-pointer data members have a default `1:1` occurence
2030 constraint, making them required.
2031 
2032 A pointer data member that is explicitly marked as required with `1:1` will be
2033 serialized as an element with an `xsi:nil` attribute, thus effectively
2034 revealing the NULL property of its value.
2035 
2036 A non-pointer data member that is explicitly marked as optional with `0:1` will
2037 be set to its default value when no XML value is presented to the deserializer.
2038 A default value can be assigned to data members that have primitive types.
2039 
2040 Consider for example:
2041 
2042 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
2043  class ns__record
2044  {
2045  public:
2046  std::shared_ptr<std::string> name; // optional (0:1)
2047  uint64_t SSN 0:1 = 999; // forced this to be optional with default 999
2048  ns__record *spouse 1:1; // forced this to be required (only married people)
2049  };
2050 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2051 
2052 This class maps to a complexType in the soapcpp2-generated schema:
2053 
2054  <complexType name="record">
2055  <sequence>
2056  <element name="name" type="xsd:string" minOccurs="0" maxOccurs="1" nillable="true"/>
2057  <element name="SSN" type="xsd:unsignedLong" minOccurs="0" maxOccurs="1" default="999"/>
2058  <element name="spouse" type="ns:record" minOccurs="1" maxOccurs="1" nillable="true"/>
2059  </sequence>
2060  </complexType>
2061 
2062 An example XML instance of `ns__record` with its `name` string value set to
2063 `Joe`, `SSN` set to its default, and `spouse` set to NULL:
2064 
2065  <ns:record xmlns:ns="urn:types" ...>
2066  <name>Joe</name>
2067  <SSN>999</SSN>
2068  <spouse xsi:nil="true"/>
2069  </ns:record>
2070 
2071 @note In general, a smart pointer is simply declared as a `volatile` template
2072 in a gSOAP header file for soapcpp2:
2073 
2074 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
2075  volatile template <class T> class NAMESPACE::shared_ptr;
2076 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2077 
2078 @note The soapcpp2 tool generates code that uses `NAMESPACE::shared_ptr` and
2079 `NAMESPACE::make_shared` to create shared pointers to objects, where
2080 `NAMESPACE` is any valid C++ namespace such as `std` and `boost` if you have
2081 Boost installed.
2082 
2083 ### Container members and their occurrence constraints {#toxsd9-9}
2084 
2085 Class and struct data member types that are containers `std::deque`,
2086 `std::list`, `std::vector` and `std::set` are serialized as a collection of
2087 the values they contain. You can also serialize dynamic arrays, which is the
2088 alternative for C to store collections of data. Let's start with STL containers.
2089 
2090 You can use `std::deque`, `std::list`, `std::vector`, and `std::set` containers
2091 by importing:
2092 
2093 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
2094  #import "import/stl.h" // import all containers
2095  #import "import/stldeque.h" // import deque
2096  #import "import/stllist.h" // import list
2097  #import "import/stlvector.h" // import vector
2098  #import "import/stlset.h" // import set
2099 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2100 
2101 For example, to use a vector data mamber to store names in a record:
2102 
2103 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
2104  #import "import/stlvector.h"
2105  class ns__record
2106  {
2107  public:
2108  std::vector<std::string> names;
2109  uint64_t SSN;
2110  };
2111 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2112 
2113 To limit the number of names in the vector within reasonable bounds, occurrence
2114 constraints are associated with the container. Occurrence constraints are of
2115 the form `minOccurs : maxOccurs`:
2116 
2117 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
2118  #import "import/stlvector.h"
2119  class ns__record
2120  {
2121  public:
2122  std::vector<std::string> names 1:10;
2123  uint64_t SSN;
2124  };
2125 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2126 
2127 This class maps to a complexType in the soapcpp2-generated schema:
2128 
2129  <complexType name="record">
2130  <sequence>
2131  <element name="name" type="xsd:string" minOccurs="1" maxOccurs="10"/>
2132  <element name="SSN" type="xsd:unsignedLong" minOccurs="1" maxOccurs="1""/>
2133  </sequence>
2134  </complexType>
2135 
2136 @note In general, a container is simply declared as a template in a gSOAP
2137 header file for soapcpp2. All class templates are considered containers
2138 (except when declared `volatile`, see smart pointers). For example,
2139 `std::vector` is declared in `gsoap/import/stlvector.h` as:
2140 
2141 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
2142  template <class T> class std::vector;
2143 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2144 
2145 @note You can define and use your own containers. The soapcpp2 tool generates
2146 code that uses the following members of the `template <typename T> class C`
2147 container:
2148 
2149 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
2150  void C::clear()
2151  C::iterator C::begin()
2152  C::const_iterator C::begin() const
2153  C::iterator C::end()
2154  C::const_iterator C::end() const
2155  size_t C::size() const
2156  C::iterator C::insert(C::iterator pos, const T& val)
2157 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2158 
2159 @note For more details see the example `simple_vector` container with
2160 documentation in the package under `gsoap/samples/template`.
2161 
2162 Because C does not support a container template library, we can use a
2163 dynamically-sized array of values. This array is declared as a size-pointer
2164 pair of members within a struct or class. The array size information is stored
2165 in a special size tag member with the name `__size` or `__sizeX`, where `X` can
2166 be any name, or by an `$int` member to identify the member as a special size
2167 tag:
2168 
2169 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
2170  struct ns__record
2171  {
2172  $int sizeofnames; // array size
2173  char* *names; // array of char* names
2174  uint64_t SSN;
2175  };
2176 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2177 
2178 This class maps to a complexType in the soapcpp2-generated schema:
2179 
2180  <complexType name="record">
2181  <sequence>
2182  <element name="name" type="xsd:string" minOccurs="0" maxOccurs="unbounded" nillable="true"/>
2183  <element name="SSN" type="xsd:unsignedLong" minOccurs="1" maxOccurs="1""/>
2184  </sequence>
2185  </complexType>
2186 
2187 To limit the number of names in the array within reasonable bounds, occurrence
2188 constraints are associated with the array size member. Occurrence constraints
2189 are of the form `minOccurs : maxOccurs`:
2190 
2191 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
2192  struct ns__record
2193  {
2194  $int sizeofnames 1:10; // array size 1..10
2195  char* *names; // array of one to ten char* names
2196  uint64_t SSN;
2197  };
2198 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2199 
2200 This class maps to a complexType in the soapcpp2-generated schema:
2201 
2202  <complexType name="record">
2203  <sequence>
2204  <element name="name" type="xsd:string" minOccurs="1" maxOccurs="10" nillable="true"/>
2205  <element name="SSN" type="xsd:unsignedLong" minOccurs="1" maxOccurs="1""/>
2206  </sequence>
2207  </complexType>
2208 
2209 ### Tagged union members {#toxsd9-10}
2210 
2211 A union member in a class or in a struct cannot be serialized unless a
2212 discriminating *variant selector* member is provided that tells the serializer
2213 which union field to serialize. This effectively creates a *tagged union*.
2214 
2215 The variant selector is associated with the union as a selector-union pair of members.
2216 The variant selector is a member with the name `__union` or `__unionX`, where
2217 `X` can be any name, or by an `$int` member to identify the member as a variant
2218 selector tag:
2219 
2220 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
2221  class ns__record
2222  {
2223  public:
2224  $int xORnORs; // variant selector with values SOAP_UNION_fieldname
2225  union choice
2226  {
2227  float x;
2228  int n;
2229  char *s;
2230  } u;
2231  std::string name;
2232  };
2233 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2234 
2235 The variant selector values are auto-generated based on the union name `choice`
2236 and the names of its members `x`, `n`, and `s`:
2237 
2238 - `xORnORs = SOAP_UNION_choice_x` when `u.x` is valid.
2239 - `xORnORs = SOAP_UNION_choice_n` when `u.n` is valid.
2240 - `xORnORs = SOAP_UNION_choice_s` when `u.s` is valid.
2241 - `xORnORs = 0` when none are valid (should only be used with great care,
2242  because XML content validation may fail when content is required but absent).
2243 
2244 This class maps to a complexType with a sequence and choice in the
2245 soapcpp2-generated schema:
2246 
2247  <complexType name="record">
2248  <sequence>
2249  <choice>
2250  <element name="x" type="xsd:float" minOccurs="1" maxOccurs="1"/>
2251  <element name="n" type="xsd:int" minOccurs="1" maxOccurs="1"/>
2252  <element name="s" type="xsd:string" minOccurs="0" maxOccurs="1" nillable="true"/>
2253  </choice>
2254  <element name="names" type="xsd:string" minOccurs="1" maxOccurs="1" nillable="true"/>
2255  </sequence>
2256  </complexType>
2257 
2258 An STL container or dynamic array of a union requires wrapping the variant
2259 selector and union member in a struct:
2260 
2261 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
2262  class ns__record
2263  {
2264  public:
2265  std::vector<
2266  struct ns__data // data with a choice of x, n, or s
2267  {
2268  $int xORnORs; // variant selector with values SOAP_UNION_fieldname
2269  union choice
2270  {
2271  float x;
2272  int n;
2273  char *s;
2274  } u;
2275  }> data; // vector with data
2276  };
2277 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2278 
2279 and an equivalent definition with a dynamic array instead of a `std::vector`
2280 (you can use this in C with structs):
2281 
2282 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
2283  class ns__record
2284  {
2285  public:
2286  $int sizeOfdata; // size of dynamic array
2287  struct ns__data // data with a choice of x, n, or s
2288  {
2289  $int xORnORs; // variant selector with values SOAP_UNION_fieldname
2290  union choice
2291  {
2292  float x;
2293  int n;
2294  char *s;
2295  } u;
2296  } *data; // points to the data array of length sizeOfdata
2297  };
2298 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2299 
2300 This maps to two complexTypes in the soapcpp2-generated schema:
2301 
2302  <complexType name="data">
2303  <choice>
2304  <element name="x" type="xsd:float" minOccurs="1" maxOccurs="1"/>
2305  <element name="n" type="xsd:int" minOccurs="1" maxOccurs="1"/>
2306  <element name="s" type="xsd:string" minOccurs="0" maxOccurs="1" nillable="true"/>
2307  </choice>
2308  </complexType>
2309  <complexType name="record">
2310  <sequence>
2311  <element name="data" type="ns:data" minOccurs="0" maxOccurs="unbounded"/>
2312  </sequence>
2313  </complexType>
2314 
2315 The XML value space consists of a sequence of item elements each wrapped in an
2316 data element:
2317 
2318  <ns:record xmlns:ns="urn:types" ...>
2319  <data>
2320  <n>123</n>
2321  </data>
2322  <data>
2323  <x>3.1</x>
2324  </data>
2325  <data>
2326  <s>hello</s>
2327  </data>
2328  <data>
2329  <s>world</s>
2330  </data>
2331  </ns:record>
2332 
2333 To remove the wrapping data element, simply rename the wrapping struct and
2334 member to `__data` to make this member invisible to the serializer with the
2335 double underscore prefix naming convention. Also use a dynamic array instead
2336 of a STL container (you can use this in C with structs):
2337 
2338 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
2339  class ns__record
2340  {
2341  public:
2342  $int sizeOfdata; // size of dynamic array
2343  struct __data // contains choice of x, n, or s
2344  {
2345  $int xORnORs; // variant selector with values SOAP_UNION_fieldname
2346  union choice
2347  {
2348  float x;
2349  int n;
2350  char *s;
2351  } u;
2352  } *__data; // points to the data array of length sizeOfdata
2353  };
2354 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2355 
2356 This maps to a complexType in the soapcpp2-generated schema:
2357 
2358  <complexType name="record">
2359  <sequence minOccurs="0" maxOccurs="unbounded">
2360  <choice>
2361  <element name="x" type="xsd:float" minOccurs="1" maxOccurs="1"/>
2362  <element name="n" type="xsd:int" minOccurs="1" maxOccurs="1"/>
2363  <element name="s" type="xsd:string" minOccurs="0" maxOccurs="1" nillable="true"/>
2364  </choice>
2365  </sequence>
2366  </complexType>
2367 
2368 The XML value space consists of a sequence of `<x>`, `<n>`, and/or `<s>`
2369 elements:
2370 
2371  <ns:record xmlns:ns="urn:types" ...>
2372  <n>123</n>
2373  <x>3.1</x>
2374  <s>hello</s>
2375  <s>world</s>
2376  </ns:record>
2377 
2378 Please note that structs, classes, and unions are unnested by soapcpp2 (as in
2379 the C standard of nested structs and unions). Therefore, the `choice` union in
2380 the `ns__record` class is redeclared at the top level despite its nesting
2381 within the `ns__record` class. This means that you will have to choose a
2382 unique name for each nested struct, class, and union.
2383 
2384 ### Tagged void pointer members {#toxsd9-11}
2385 
2386 To serialize data pointed to by `void*` requires run-time type information that
2387 tells the serializer what type of data to serialize by means of a *tagged void
2388 pointer*. This type information is stored in a special type tag member of a
2389 struct/class with the name `__type` or `__typeX`, where `X` can be any name, or
2390 alternatively by an `$int` special member of any name as a type tag:
2391 
2392 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
2393  class ns__record
2394  {
2395  public:
2396  $int typeOfdata; // type tag with values SOAP_TYPE_T
2397  void *data; // points to some data of type T
2398  };
2399 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2400 
2401 A type tag member has nonzero values `SOAP_TYPE_T` where `T` is the name of a
2402 struct/class or the name of a primitive type, such as `int`, `std__string` (for
2403 `std::string`), `string` (for `char*`).
2404 
2405 This class maps to a complexType with a sequence in the soapcpp2-generated
2406 schema:
2407 
2408  <complexType name="record">
2409  <sequence>
2410  <element name="data" type="xsd:anyType" minOccurs="0" maxOccurs="1"/>
2411  </sequence>
2412  </complexType>
2413 
2414 The XML value space consists of the XML value space of the type with the
2415 addition of an `xsi:type` attribute to the enveloping element:
2416 
2417  <ns:record xmlns:ns="urn:types" ...>
2418  <data xsi:type="xsd:int">123</data>
2419  </ns:record>
2420 
2421 This `xsi:type` attribute is important for the receiving end to distinguish
2422 the type of data to instantiate. The receiver cannot deserialize the data
2423 without an `xsd:type` attribute.
2424 
2425 You can find the `SOAP_TYPE_T` name of each serializable type in the
2426 auto-generated soapStub.h file.
2427 
2428 Also all serializable C++ classes have a virtual `int T::soap_type()` member
2429 that returns their `SOAP_TYPE_T` value that you can use.
2430 
2431 When the `void*` pointer is NULL or when `typeOfdata` is zero, the data is not
2432 serialized.
2433 
2434 An STL container or dynamic array of `void*` pointers to `xsd:anyType` data
2435 requires wrapping the type tag and `void*` members in a struct:
2436 
2437 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
2438  class ns__record
2439  {
2440  public:
2441  std::vector<
2442  struct ns__data // data with an xsd:anyType item
2443  {
2444  $int typeOfitem; // type tag with values SOAP_TYPE_T
2445  void *item; // points to some item of type T
2446  }> data; // vector with data
2447  };
2448 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2449 
2450 and an equivalent definition with a dynamic array instead of a `std::vector`
2451 (you can use this in C with structs):
2452 
2453 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
2454  class ns__record
2455  {
2456  public:
2457  $int sizeOfdata; // size of dynamic array
2458  struct ns__data // data with an xsd:anyType item
2459  {
2460  $int typeOfitem; // type tag with values SOAP_TYPE_T
2461  void *item; // points to some item of type T
2462  } *data; // points to the data array of length sizeOfdata
2463  };
2464 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2465 
2466 This maps to two complexTypes in the soapcpp2-generated schema:
2467 
2468  <complexType name="data">
2469  <sequence>
2470  <element name="item" type="xsd:anyType" minOccurs="1" maxOccurs="1" nillable="true"/>
2471  </sequence>
2472  </complexType>
2473  <complexType name="record">
2474  <sequence>
2475  <element name="data" type="ns:data" minOccurs="0" maxOccurs="unbounded"/>
2476  </sequence>
2477  </complexType>
2478 
2479 The XML value space consists of a sequence of item elements each wrapped in a
2480 data element:
2481 
2482  <ns:record xmlns:ns="urn:types" ...>
2483  <data>
2484  <item xsi:type="xsd:int">123</item>
2485  </data>
2486  <data>
2487  <item xsi:type="xsd:double">3.1</item>
2488  </data>
2489  <data>
2490  <item xsi:type="xsd:string">abc</item>
2491  </data>
2492  </ns:record>
2493 
2494 To remove the wrapping data elements, simply rename the wrapping struct and
2495 member to `__data` to make this member invisible to the serializer with the
2496 double underscore prefix naming convention. Also use a dynamic array instead
2497 of a STL container (you can use this in C with structs):
2498 
2499 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
2500  class ns__record
2501  {
2502  public:
2503  $int sizeOfdata; // size of dynamic array
2504  struct __data // contains xsd:anyType item
2505  {
2506  $int typeOfitem; // type tag with values SOAP_TYPE_T
2507  void *item; // points to some item of type T
2508  } *__data; // points to the data array of length sizeOfdata
2509  };
2510 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2511 
2512 This maps to a complexType in the soapcpp2-generated schema:
2513 
2514  <complexType name="record">
2515  <sequence minOccurs="0" maxOccurs="unbounded">
2516  <element name="item" type="xsd:anyType" minOccurs="1" maxOccurs="1"/>
2517  </sequence>
2518  </complexType>
2519 
2520 The XML value space consists of a sequence of data elements:
2521 
2522  <ns:record xmlns:ns="urn:types" ...>
2523  <item xsi:type="xsd:int">123</item>
2524  <item xsi:type="xsd:double">3.1</item>
2525  <item xsi:type="xsd:string">abc</item>
2526  </ns:record>
2527 
2528 Again, please note that structs, classes, and unions are unnested by soapcpp2
2529 (as in the C standard of nested structs and unions). Therefore, the `__data`
2530 struct in the `ns__record` class is redeclared at the top level despite its
2531 nesting within the `ns__record` class. This means that you will have to choose
2532 a unique name for each nested struct, class, and union.
2533 
2534 @see Section [XSD type bindings](#typemap2).
2535 
2536 ### Adding get and set methods {#toxsd9-12}
2537 
2538 A public `get` method may be added to a class or struct, which will be
2539 triggered by the deserializer. This method will be invoked right after the
2540 instance is populated by the deserializer. The `get` method can be used to
2541 update or verify deserialized content. It should return `SOAP_OK` or set
2542 `soap::error` to a nonzero error code and return it.
2543 
2544 A public `set` method may be added to a class or struct, which will be
2545 triggered by the serializer. The method will be invoked just before the
2546 instance is serialized. Likewise, the `set` method should return `SOAP_OK` or
2547 set set `soap::error` to a nonzero error code and return it.
2548 
2549 For example, adding a `set` and `get` method to a class declaration:
2550 
2551 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
2552  class ns__record
2553  {
2554  public:
2555  int set(struct soap*); // triggered before serialization
2556  int get(struct soap*); // triggered after deserialization
2557  ...
2558  };
2559 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2560 
2561 To add these and othe rmethods to classes and structs with wsdl2h and
2562 `typemap.dat`, please see [class/struct member additions](#typemap3).
2563 
2564 ### Operations on classes and structs {#toxsd9-13}
2565 
2566 The following functions/macros are generated by soapcpp2 for each type `T`,
2567 which should make it easier to send, receive, and copy XML data in C and in
2568 C++:
2569 
2570 - `int soap_write_T(struct soap*, T*)` writes an instance of `T` to a file via
2571  file descriptor `int soap::sendfd)` or to a stream via `std::ostream
2572  *soap::os` (C++ only) or saves into a NUL-terminated string by setting
2573  `const char **soap::os` to a string pointer to be set (C only). Returns
2574  `SOAP_OK` on success or an error code, also stored in `soap->error`.
2575 
2576 - `int soap_read_T(struct soap*, T*)` reads an instance of `T` from a file via
2577  file descriptor `int soap::recvfd)` or from a stream via `std::istream
2578  *soap::is` (C++ only) or reads from a NUL-termianted string `const char
2579  *soap::is` (C only). Returns `SOAP_OK` on success or an error code, also
2580  stored in `soap->error`.
2581 
2582 - `void soap_default_T(struct soap*, T*)` sets an instance `T` to its default
2583  value, resetting members of a struct to their initial values (for classes we
2584  use method `T::soap_default`, see below).
2585 
2586 - `T * soap_dup_T(struct soap*, T *dst, const T *src)` (soapcpp2 option `-Ec`)
2587  deep copy `src` into `dst`, replicating all deep cycles and shared pointers
2588  when a managing soap context is provided as argument. When `dst` is NULL,
2589  allocates space for `dst`. Deep copy is a tree when argument is NULL, but the
2590  presence of deep cycles will lead to non-termination. Use flag
2591  `SOAP_XML_TREE` with managing context to copy into a tree without cycles and
2592  pointers to shared objects. Returns `dst` (or allocated space when `dst` is
2593  NULL).
2594 
2595 - `void soap_del_T(const T*)` (soapcpp2 option `-Ed`) deletes all
2596  heap-allocated members of this object by deep deletion ONLY IF this object
2597  and all of its (deep) members are not managed by a soap context AND the deep
2598  structure is a tree (no cycles and co-referenced objects by way of multiple
2599  (non-smart) pointers pointing to the same data). Can be safely used after
2600  `soap_dup(NULL)` to delete the deep copy. Does not delete the object itself.
2601 
2602 When in C++ mode, soapcpp2 tool adds several methods to classes in addition to
2603 adding a default constructor and destructor (when these were not explicitly
2604 declared).
2605 
2606 The public methods added to a class `T`:
2607 
2608 - `virtual int T::soap_type(void)` returns a unique type ID (`SOAP_TYPE_T`).
2609  This numeric ID can be used to distinguish base from derived instances.
2610 
2611 - `virtual void T::soap_default(struct soap*)` sets all data members to
2612  default values.
2613 
2614 - `virtual void T::soap_serialize(struct soap*) const` serializes object to
2615  prepare for SOAP 1.1/1.2 encoded output (or with `SOAP_XML_GRAPH`) by
2616  analyzing its (cyclic) structures.
2617 
2618 - `virtual int T::soap_put(struct soap*, const char *tag, const char *type) const`
2619  emits object in XML, compliant with SOAP 1.1 encoding style, return error
2620  code or `SOAP_OK`. Requires `soap_begin_send(soap)` and
2621  `soap_end_send(soap)`.
2622 
2623 - `virtual int T::soap_out(struct soap*, const char *tag, int id, const char *type) const`
2624  emits object in XML, with tag and optional id attribute and `xsi:type`,
2625  return error code or `SOAP_OK`. Requires `soap_begin_send(soap)` and
2626  `soap_end_send(soap)`.
2627 
2628 - `virtual void * T::soap_get(struct soap*, const char *tag, const char *type)`
2629  Get object from XML, compliant with SOAP 1.1 encoding style, return pointer
2630  to object or NULL on error. Requires `soap_begin_recv(soap)` and
2631  `soap_end_recv(soap)`.
2632 
2633 - `virtual void *soap_in(struct soap*, const char *tag, const char *type)`
2634  Get object from XML, with matching tag and type (NULL matches any tag and
2635  type), return pointer to object or NULL on error. Requires
2636  `soap_begin_recv(soap)` and `soap_end_recv(soap)`
2637 
2638 - `virtual T * T::soap_alloc(void) const` returns a new object of type `T`,
2639  default initialized and not managed by a soap context.
2640 
2641 - `virtual T * T::soap_dup(struct soap*) const` (soapcpp2 option `-Ec`) returns
2642  a duplicate of this object by deep copying, replicating all deep cycles and
2643  shared pointers when a managing soap context is provided as argument. Deep
2644  copy is a tree when argument is NULL, but the presence of deep cycles will
2645  lead to non-termination. Use flag `SOAP_XML_TREE` with the managing context
2646  to copy into a tree without cycles and pointers to shared objects.
2647 
2648 - `virtual void T::soap_del() const` (soapcpp2 option `-Ed`) deletes all
2649  heap-allocated members of this object by deep deletion ONLY IF this object
2650  and all of its (deep) members are not managed by a soap context AND the deep
2651  structure is a tree (no cycles and co-referenced objects by way of multiple
2652  (non-smart) pointers pointing to the same data). Can be safely used after
2653  `soap_dup(NULL)` to delete the deep copy. Does not delete the object itself.
2654 
2655 Also for C++, there are four variations of `soap_new_T` for
2656 class/struct/template type `T` that soapcpp2 auto-generates to create instances
2657 on a context-managed heap:
2658 
2659 - `T * soap_new_T(struct soap*)` returns a new instance of `T` with default data
2660  member initializations that are set with the soapcpp2 auto-generated `void
2661  T::soap_default(struct soap*)` method), but ONLY IF the soapcpp2
2662  auto-generated default constructor is used that invokes `soap_default()` and
2663  was not replaced by a user-defined default constructor.
2664 
2665 - `T * soap_new_T(struct soap*, int n)` returns an array of `n` new instances of
2666  `T`. Similar to the above, instances are initialized.
2667 
2668 - `T * soap_new_req_T(struct soap*, ...)` returns a new instance of `T` and sets
2669  the required data members to the values specified in `...`. The required data
2670  members are those with nonzero minOccurs, see the subsections on
2671  [(smart) pointer members and their occurrence constraints](#toxsd9-8) and
2672  [container members and their occurrence constraints](#toxsd9-9).
2673 
2674 - `T * soap_new_set_T(struct soap*, ...)` returns a new instance of `T` and sets
2675  the public/serializable data members to the values specified in `...`.
2676 
2677 The above functions can be invoked with a NULL `soap` context, but we will be
2678 responsible to use `delete T` to remove this instance from the unmanaged heap.
2679 
2680 Special classes and structs {#toxsd10}
2681 ---------------------------
2682 
2683 ### SOAP encoded arrays {#toxsd10-1}
2684 
2685 A class or struct with the following layout is a one-dimensional SOAP encoded
2686 Array type:
2687 
2688 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
2689  class ArrayOfT
2690  {
2691  public:
2692  T *__ptr; // array pointer
2693  int __size; // array size
2694  };
2695 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2696 
2697 where `T` is the array element type. A multidimensional SOAP Array is:
2698 
2699 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
2700  class ArrayOfT
2701  {
2702  public:
2703  T *__ptr; // array pointer
2704  int __size[N]; // array size of each dimension
2705  };
2706 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2707 
2708 where `N` is the constant number of dimensions. The pointer points to an array
2709 of `__size[0]*__size[1]* ... * __size[N-1]` elements.
2710 
2711 This maps to a complexType restriction of SOAP-ENC:Array in the
2712 soapcpp2-generated schema:
2713 
2714  <complexType name="ArrayOfT">
2715  <complexContent>
2716  <restriction base="SOAP-ENC:Array">
2717  <sequence>
2718  <element name="item" type="T" minOccurs="0" maxOccurs="unbounded" nillable="true"/>
2719  </sequence>
2720  <attribute ref="SOAP-ENC:arrayType" WSDL:arrayType="ArrayOfT[]"/>
2721  </restriction>
2722  </complexContent>
2723  </complexType>
2724 
2725 The name of the class can be arbitrary. We often use `ArrayOfT` without a
2726 prefix to distinguish arrays from other classes and structs.
2727 
2728 With SOAP 1.1 encoding, an optional offset member can be added that controls
2729 the start of the index range for each dimension:
2730 
2731 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
2732  class ArrayOfT
2733  {
2734  public:
2735  T *__ptr; // array pointer
2736  int __size[N]; // array size of each dimension
2737  int __offset[N]; // array offsets to start each dimension
2738  };
2739 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2740 
2741 For example, we can define a matrix of floats as follows:
2742 
2743 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
2744  class Matrix
2745  {
2746  public:
2747  double *__ptr;
2748  int __size[2];
2749  };
2750 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2751 
2752 The following code populates the matrix and serializes it in XML:
2753 
2754 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
2755  soap *soap = soap_new1(SOAP_XML_INDENT);
2756  Matrix A;
2757  double a[6] = { 1, 2, 3, 4, 5, 6 };
2758  A.__ptr = a;
2759  A.__size[0] = 2;
2760  A.__size[1] = 3;
2761  soap_write_Matrix(soap, &A);
2762 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2763 
2764 Matrix A is serialized as an array with 2x3 values:
2765 
2766  <SOAP-ENC:Array SOAP-ENC:arrayType="xsd:double[2,3]" ...>
2767  <item>1</item>
2768  <item>2</item>
2769  <item>3</item>
2770  <item>4</item>
2771  <item>5</item>
2772  <item>6</item>
2773  </SOAP-ENC:Array>
2774 
2775 ### XSD hexBinary and base64Binary types {#toxsd10-2}
2776 
2777 A special case of a one-dimensional array is used to define `xsd:hexBinary` and
2778 `xsd:base64Binary` types when the pointer type is `unsigned char`:
2779 
2780 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
2781  class xsd__hexBinary
2782  {
2783  public:
2784  unsigned char *__ptr; // points to raw binary data
2785  int __size; // size of data
2786  };
2787 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2788 
2789 and
2790 
2791 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
2792  class xsd__base64Binary
2793  {
2794  public:
2795  unsigned char *__ptr; // points to raw binary data
2796  int __size; // size of data
2797  };
2798 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2799 
2800 ### MIME/MTOM attachment binary types {#toxsd10-3}
2801 
2802 A class or struct with a binary content layout can be extended to support
2803 MIME/MTOM (and older DIME) attachments, such as in xop:Include elements:
2804 
2805 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
2806  //gsoap xop schema import: http://www.w3.org/2004/08/xop/include
2807  class _xop__Include
2808  {
2809  public:
2810  unsigned char *__ptr; // points to raw binary data
2811  int __size; // size of data
2812  char *id; // NULL to generate an id, or set to a unique UUID
2813  char *type; // MIME type of the data
2814  char *options; // optional description of MIME attachment
2815  };
2816 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2817 
2818 Attachments are beyond the scope of this document. See the
2819 [gSOAP user guide](http://www.genivia.com/doc/soapdoc2.html) for more details.
2820 
2821 ### Wrapper class/struct with simpleContent {#toxsd10-4}
2822 
2823 A class or struct with the following layout is a complexType that wraps
2824 simpleContent:
2825 
2826 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
2827  class ns__simple
2828  {
2829  public:
2830  T __item;
2831  };
2832 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2833 
2834 The type `T` is a primitive type (`bool`, `enum`, `time_t`, numeric and string
2835 types), `xsd__hexBinary`, `xsd__base64Binary`, and custom serializers, such as
2836 `xsd__dateTime`.
2837 
2838 This maps to a complexType with simpleContent in the soapcpp2-generated schema:
2839 
2840  <complexType name="simple">
2841  <simpleContent>
2842  <extension base="T"/>
2843  </simpleContent>
2844  </complexType>
2845 
2846 A wrapper class/struct may include any number of attributes declared with `@`.
2847 
2848 ### DOM anyType and anyAttribute {#toxsd10-5}
2849 
2850 Use of a DOM is optional and enabled by `#import "dom.h"` to use the DOM
2851 `xsd__anyType` element node and `xsd__anyAttribute` attribute node:
2852 
2853 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
2854  #import "dom.h"
2855 
2856  class ns__record
2857  {
2858  public:
2859  @xsd__anyAttribute attributes; // list of DOM attributes
2860  ...
2861  xsd__anyType *name; // optional DOM element
2862  };
2863 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2864 
2865 where `name` contains XML stored in a DOM node set and `attributes` is a list
2866 of all visibly rendered attributes. The name `attributes` is arbitrary and any
2867 name will suffice.
2868 
2869 You should place the `xsd__anyType` members at the end of the struct or class.
2870 This ensures that the DOM members are populated last as a "catch all". A
2871 member name starting with double underscore is a wildcard member name and
2872 matches any XML tag. These members are placed at the end of a struct or class
2873 automatically by soapcpp2.
2874 
2875 An `#import "dom.h"` import is automatically added by wsdl2h with option `-d`
2876 to bind `xsd:anyType` to DOM nodes, and also to populate `xsd:any`,
2877 `xsd:anyAttribute` and `xsd:mixed` XML content:
2878 
2879 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
2880  #import "dom.h"
2881 
2882  class ns__record
2883  {
2884  public:
2885  ...
2886  @xsd__anyAttribute __anyAttribute; // optional DOM attributes
2887  std::vector<xsd__anyType> __any 0; // optional DOM elements
2888  xsd__anyType __mixed 0; // optional mixed content
2889  };
2890 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2891 
2892 where the members prefixed with `__` are "invisible" to the XML parser, meaning
2893 that these members are not bound to XML tag names.
2894 
2895 In C you can use a dynamic arrary instead of `std::vector`:
2896 
2897 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.c}
2898  #import "dom.h"
2899 
2900  struct ns__record
2901  {
2902  ...
2903  @xsd__anyAttribute __anyAttribute; // optional DOM attributes
2904  $int __sizeOfany; // size of the array
2905  xsd__anyType *__any; // optional DOM elements
2906  xsd__anyType __mixed 0; // optional mixed content
2907  };
2908 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2909 
2910 Classes can inherit DOM, which enables full use of polymorphism with one base
2911 DOM class:
2912 
2913 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
2914  #import "dom.h"
2915 
2916  class ns__record : public xsd__anyType
2917  {
2918  ...
2919  std::vector<xsd__anyType*> array; // array of objects of any class
2920  };
2921 
2922 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2923 
2924 This permits an `xsd__anyType` pointer to refer to a derived class such as
2925 `ns__record`, which will be serialized with an `xsi:type` attribute that is
2926 set to "ns:record". The `xsi:type` attributes add the necessary type information
2927 to distinguish the XML content from the DOM base type. This is important for
2928 the receiving end: without `xsd:type` attributes with type names, only base DOM
2929 objects are recognized and instantiated.
2930 
2931 Because C lacks OOP principles such as class inheritance and polymorphism, you
2932 will need to use the special [`void*` members](#toxsd9-11) to serialize data
2933 pointed to by a `void*` member.
2934 
2935 To ensure that wsdl2h generates pointer-based `xsd__anyType` DOM nodes with
2936 option `-d` for `xsd:any`, add the following line to `typemap.dat`:
2937 
2938  xsd__any = | xsd__anyType*
2939 
2940 This lets wsdl2h produce class/struct members and containers with
2941 `xsd__anyType*` for `xsd:any` instead of `xsd__anyType`. To just force all
2942 `xsd:anyType` uses to be pointer-based, declare in `typemap.dat`:
2943 
2944  xsd__anyType = | xsd__anyType*
2945 
2946 If you use wsdl2h with option `-p` with option `-d` then every class will
2947 inherit DOM as shown above. Without option `-d`, an `xsd__anyType` type is
2948 generated to serve as the root type in the type hierarchy:
2949 
2950 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
2951  class xsd__anyType { _XML __item; struct soap *soap; };
2952 
2953  class ns__record : public xsd__anyType
2954  {
2955  ...
2956  };
2957 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2958 
2959 where the `_XML __item` member holds any XML content as a literal XML string.
2960 
2961 To use the DOM API, compile `dom.c` (or `dom.cpp` for C++), or link with
2962 `-lgsoapssl` (or `-lgsoapssl++` for C++).
2963 
2964 @see Documentation of [XML DOM and XPath](http://www.genivia.com/doc/dom/html)
2965 for more details.
2966 
2967 Directives {#directives}
2968 ==========
2969 
2970 You can use `//gsoap` directives in the gSOAP header file with the data binding
2971 interface for soapcpp2. These directives are used to configure the code
2972 generated by soapcpp2 by declaring various. properties of Web services and XML
2973 schemas. When using the wsdl2h tool, you will notice that wsdl2h generates
2974 directives automatically based on the WSDL and XSD input.
2975 
2976 Service directives are applicable to service and operations described by WSDL.
2977 Schema directives are applicable to types, elements, and attributes defined by
2978 XML schemas.
2979 
2980 Service directives {#directives-1}
2981 ------------------
2982 
2983 A service directive must start at a new line and is of the form:
2984 
2985 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
2986  //gsoap <prefix> service <property>: <value>
2987 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2988 
2989 where `<prefix>` is the XML namespace prefix of a service binding. The
2990 `<property>` and `<value>` fields are one of the following:
2991 
2992 | Property | Value |
2993 | --------------- | -------------------------------------------------------------------------------- |
2994 | `name` | name of the service, optionally followed by text describing the service |
2995 | `namespace` | URI of the WSDL targetNamespace |
2996 | `documentation` | text describing the service (see also the `name` property), multiple permitted |
2997 | `doc` | same as above, shorthand form |
2998 | `style` | `document` (default) SOAP messaging style or `rpc` for SOAP RPC |
2999 | `encoding` | `literal` (default), `encoded` for SOAP encoding, or a custom URI |
3000 | `protocol` | specifies SOAP or REST, see below |
3001 | `port` | URL of the service endpoint, usually an http or https address |
3002 | `transport` | URI declaration of the transport, usually `http://schemas.xmlsoap.org/soap/http` |
3003 | `definitions` | name of the WSDL definitions/\@name |
3004 | `type` | name of the WSDL definitions/portType/\@name (WSDL2.0 interface/\@name) |
3005 | `binding` | name of the WSDL definitions/binding/\@name |
3006 | `portName` | name of the WSDL definitions/service/port/\@name |
3007 | `portType` | an alias for the `type` property |
3008 | `interface` | an alias for the `type` property |
3009 | `location` | an alias for the `port` property |
3010 | `endpoint` | an alias for the `port` property |
3011 
3012 The service `name` and `namespace` properties are required in order to generate
3013 a valid WSDL with soapcpp2. The other properties are optional.
3014 
3015 The `style` and `encoding` property defaults are changed with soapcpp2 option
3016 `-e` to `rpc` and `encoded`, respectively.
3017 
3018 The `protocol` property is `SOAP` by default (SOAP 1.1). Protocol property
3019 values are:
3020 
3021 | Protocol Value | Description |
3022 | -------------- | ---------------------------------------------------- |
3023 | `SOAP` | SOAP transport, supporting both SOAP 1.1 and 1.2 |
3024 | `SOAP1.1` | SOAP 1.1 transport (same as soapcpp2 option `-1`) |
3025 | `SOAP1.2` | SOAP 1.2 transport (same as soapcpp2 option `-2`) |
3026 | `SOAP-GET` | one-way SOAP 1.1 or 1.2 with HTTP GET |
3027 | `SOAP1.1-GET` | one-way SOAP 1.1 with HTTP GET |
3028 | `SOAP1.2-GET` | one-way SOAP 1.2 with HTTP GET |
3029 | `HTTP` | non-SOAP REST protocol with HTTP POST |
3030 | `POST` | non-SOAP REST protocol with HTTP POST |
3031 | `GET` | non-SOAP REST protocol with HTTP GET |
3032 | `PUT` | non-SOAP REST protocol with HTTP PUT |
3033 | `DELETE` | non-SOAP REST protocol with HTTP DELETE |
3034 
3035 You can bind service operations to the WSDL namespace of a service by using the
3036 namespace prefix as part of the identifier name of the function that defines
3037 the service operation:
3038 
3039 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
3040  int prefix__func(arg1, arg2, ..., argn, result);
3041 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3042 
3043 You can override the `port` endpoint URL at runtime in the auto-generated
3044 `soap_call_prefix__func` service call (C/C++ client side) and in the C++ proxy
3045 class service call.
3046 
3047 Service method directives {#directives-2}
3048 -------------------------
3049 
3050 Service properties are applicable to a service and to all of its operations.
3051 Service method directives are specifically applicable to a service operation.
3052 
3053 A service method directive is of the form:
3054 
3055 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
3056  //gsoap <prefix> service method-<property>: <method> <value>
3057 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3058 
3059 where `<prefix>` is the XML namespace prefix of a service binding and
3060 `<method>` is the unqualified name of a service operation. The `<property>`
3061 and `<value>` fields are one of the following:
3062 
3063 | Method Property | Value |
3064 | --------------------------- | ------------------------------------------------------------------------------ |
3065 | `method-documentation` | text describing the service operation |
3066 | `method` | same as above, shorthand form |
3067 | `method-action` | `""` or URI SOAPAction HTTP header, or URL query string for REST protocols |
3068 | `method-input-action` | `""` or URI SOAPAction HTTP header of service request messages |
3069 | `method-output-action` | `""` or URI SOAPAction HTTP header of service response messages |
3070 | `method-fault-action` | `""` or URI SOAPAction HTTP header of service fault messages |
3071 | `method-header-part` | member name of the `SOAP_ENV__Header` struct used in SOAP Header |
3072 | `method-input-header-part` | member name of the `SOAP_ENV__Header` struct used in SOAP Headers of requests |
3073 | `method-output-header-part` | member name of the `SOAP_ENV__Header` struct used in SOAP Headers of responses |
3074 | `method-fault` | type name of a struct or class member used in `SOAP_ENV__Details` struct |
3075 | `method-mime-type` | REST content type or SOAP MIME attachment content type(s) |
3076 | `method-input-mime-type` | REST content type or SOAP MIME attachment content type(s) of request message |
3077 | `method-output-mime-type` | REST content type or SOAP MIME attachment content type(s) of response message |
3078 | `method-style` | `document` or `rpc` |
3079 | `method-encoding` | `literal`, `encoded`, or a custom URI for encodingStyle of messages |
3080 | `method-response-encoding` | `literal`, `encoded`, or a custom URI for encodingStyle of response messages |
3081 | `method-protocol` | SOAP or REST, see [service directives](#directives-1) |
3082 
3083 The `method-header-part` properties can be repeated for a service operation to
3084 declare multiple SOAP Header parts that the service operation requires. You
3085 can use `method-input-header-part` and `method-output-header-part` to
3086 differentiate between request and response messages.
3087 
3088 The `method-fault` property can be repeated for a service operation to declare
3089 multiple faults that the service operation may return.
3090 
3091 The `method-action` property serves two purposes:
3092 
3093 -# To set the SOAPAction header for SOAP protocols, i.e. sets the
3094  definitions/binding/operation/SOAP:operation/\@soapAction.
3095 
3096 -# To set the URL query string for endpoints with REST protocols, i.e. sets the
3097  definitions/binding/operation/HTTP:operation/\@location, which specifies
3098  a URL query string (starts with a `?`) to complete the service endpoint URL
3099  or extends the endpoint URL with a local path (starts with a `/`).
3100 
3101 Use `method-input-action` and `method-output-action` to differentiate the
3102 SOAPAction between SOAP request and response messages.
3103 
3104 You can always override the port endpoint URL and action values at runtime in
3105 the auto-generated `soap_call_prefix__func` service call (C/C++ client side)
3106 and in the auto-generated C++ proxy class service calls. A runtime NULL
3107 endpoint URL and/or action uses the defaults set by these directives.
3108 
3109 The `method-mime-type` property serves two purposes:
3110 
3111 -# To set the type of MIME/MTOM attachments used with SOAP protocols. Multiple
3112  attachment types can be declared for a SOAP service operation, i.e. adds
3113  definitions/binding/operation/input/MIME:multipartRelated/MIME:part/MIME:content/\@type
3114  for each type specified.
3115 
3116 -# To set the MIME type of a REST operation. This replaces XML declared in
3117  WSDL by definitions/binding/operation/(input|output)/MIME:mimeXml with
3118  MIME:content/\@type. Use `application/x-www-form-urlencoded` with REST POST
3119  and PUT protocols to send encoded form data automatically instead of XML.
3120  Only primitive type values can be transmitted with form data, such as
3121  numbers and strings, i.e. only types that are legal to use as
3122  [attributes members](#toxsd9-5).
3123 
3124 Use `method-input-mime-type` and `method-output-mime-type` to differentiate the
3125 attachment types between SOAP request and response messages.
3126 
3127 Schema directives {#directives-3}
3128 -----------------
3129 
3130 A schema directive is of the form:
3131 
3132 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
3133  //gsoap <prefix> schema <property>: <value>
3134 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3135 
3136 where `<prefix>` is the XML namespace prefix of a schema. The `<property>` and
3137 `<value>` fields are one of the following:
3138 
3139 | Property | Value |
3140 | --------------- | --------------------------------------------------------------------------------- |
3141 | `namespace` | URI of the XSD targetNamespace |
3142 | `namespace2` | alternate URI for the XSD namespace (i.e. URI is also accepted by the XML parser) |
3143 | `import` | URI of imported namespace |
3144 | `form` | `unqualified` (default) or `qualified` local element and attribute form defaults |
3145 | `elementForm` | `unqualified` (default) or `qualified` local element form default |
3146 | `attributeForm` | `unqualified` (default) or `qualified` local attribute form default |
3147 | `typed` | `no` (default) or `yes` for serializers to add `xsi:type` attributes to XML |
3148 
3149 To learn more about the local form defaults, see [qualified and unqualified members.](#toxsd9-6)
3150 
3151 The `typed` property is implicitly `yes` when soapcpp2 option `-t` is used.
3152 
3153 Schema type directives {#directives-4}
3154 ----------------------
3155 
3156 A schema type directive is of the form:
3157 
3158 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
3159  //gsoap <prefix> schema type-<property>: <name> <value>
3160  //gsoap <prefix> schema type-<property>: <name>::<member> <value>
3161 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3162 
3163 where `<prefix>` is the XML namespace prefix of a schema and `<name>` is an
3164 unqualified name of a C/C++ type, and the optional `<member>` is a class/struct
3165 members or enum constant.
3166 
3167 You can describe a type:
3168 
3169 | Type Property | Value |
3170 | -------------------- | ------------------------------- |
3171 | `type-documentation` | text describing the schema type |
3172 | `type` | same as above, shorthand form |
3173 
3174 For example, you can add a description to an enumeration:
3175 
3176 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
3177  //gsoap ns schema type: Vowels The letters A, E, I, O, U, and sometimes Y
3178  //gsoap ns schema type: Vowels::Y A vowel, sometimes
3179  enum class ns__Vowels : char { A = 'A', E = 'E', I = 'I', O = 'O', U = 'U', Y = 'Y' };
3180 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3181 
3182 This documented enumeration maps to a simpleType restriction of `xsd:string` in
3183 the soapcpp2-generated schema:
3184 
3185  <simpleType name="Vowels">
3186  <annotation>
3187  <documentation>The letters A, E, I, O, U, and sometimes Y</documentation>
3188  </annotation>
3189  <restriction base="xsd:string">
3190  <enumeration value="A"/>
3191  <enumeration value="E"/>
3192  <enumeration value="I"/>
3193  <enumeration value="O"/>
3194  <enumeration value="U"/>
3195  <enumeration value="Y">
3196  <annotation>
3197  <documentation>A vowel, sometimes</documentation>
3198  </annotation>
3199  <enumeration/>
3200  </restriction>
3201  </simpleType>
3202 
3203 Serialization rules {#rules}
3204 ===================
3205 
3206 A presentation on XML data bindings is not complete without discussing the
3207 serialization rules and options that put your data in XML on the wire or store
3208 it a file or buffer.
3209 
3210 There are several options to choose from to serialize data in XML. The choice
3211 depends on the use of the SOAP protocol or if SOAP is not required. The wsdl2h
3212 tool automates this for you by taking the WSDL transport bindings into account
3213 when generating the service functions in C and C++ that use SOAP or REST.
3214 
3215 The gSOAP tools are not limited to SOAP. The tools implement generic XML data
3216 bindings for SOAP, REST, and other uses of XML. So you can read and write XML
3217 using the serializing [operations on classes and structs](#toxsd9-13).
3218 
3219 The following sections briefly explain the serialization rules with respect to
3220 the SOAP protocol for XML Web services. A basic understanding of the SOAP
3221 protocol is useful when developing client and server applications that must
3222 interoperate with other SOAP applications.
3223 
3224 SOAP/REST Web service client and service operations are represented as
3225 functions in your gSOAP header file with the data binding interface for
3226 soapcpp2. The soapcpp2 tool will translate these function to client-side
3227 service invocation calls and server-side service operation dispatchers.
3228 
3229 A discussion of SOAP clients and servers is beyond the scope of this document.
3230 However, the SOAP options discussed here also apply to SOAP client and server
3231 development.
3232 
3233 SOAP document versus rpc style {#doc-rpc}
3234 ------------------------------
3235 
3236 The `wsdl:binding/soap:binding/@style` attribute in the wsdl:binding section of
3237 a WSDL is either "document" or "rpc". The "rpc" style refers to SOAP RPC
3238 (Remote Procedure Call), which is more restrictive than the "document" style by
3239 requiring one XML element in the SOAP Body to act as the procedure name with
3240 XML subelements as its parameters.
3241 
3242 For example, the following directives in the gSOAP header file for soapcpp2
3243 declare that `DBupdate` is a SOAP RPC encoding service method:
3244 
3245 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
3246  //gsoap ns service namespace: urn:DB
3247  //gsoap ns service method-protocol: DBupdate SOAP
3248  //gsoap ns service method-style: DBupdate rpc
3249  int ns__DBupdate(...);
3250 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3251 
3252 The XML payload has a SOAP envelope, optional SOAP header, and a SOAP body with
3253 one element representing the operation with the parameters as subelements:
3254 
3255  <SOAP-ENV:Envelope
3256  xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
3257  xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"
3258  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3259  xmlns:xsd="http://www.w3.org/2001/XMLSchema"
3260  xmlsn:ns="urn:DB">
3261  <SOAP-ENV:Body>
3262  <ns:DBupdate>
3263  ...
3264  </ns:DBupdate>
3265  </SOAP-ENV:Body>
3266  </SOAP-ENV:Envelope>
3267 
3268 The "document" style puts no restrictions on the SOAP Body content. However, we
3269 recommend that the first element's tag name in the SOAP Body should be unique
3270 to each type of operation, so that the receiver can dispatch the operation
3271 based on this element's tag name. Alternatively, the HTTP URL path can be used
3272 to specify the operation, or the HTTP action header can be used to dispatch
3273 operations automatically on the server side (soapcpp2 options -a and -A).
3274 
3275 SOAP literal versus encoding {#lit-enc}
3276 ----------------------------
3277 
3278 The `wsdl:operation/soap:body/@use` attribute in the wsdl:binding section of a
3279 WSDL is either "literal" or "encoded". The "encoded" use refers to the SOAP
3280 encoding rules that support id-ref multi-referenced elements to serialize
3281 data as graphs.
3282 
3283 SOAP encoding is very useful if the data internally forms a graph (including
3284 cycles) and we want the graph to be serialized in XML in a format that ensures
3285 that its structure is preserved. In that case, SOAP 1.2 encoding is the best
3286 option.
3287 
3288 SOAP encoding also adds encoding rules for [SOAP arrays](toxsd10) to serialize
3289 multi-dimensional arrays. The use of XML attributes to exchange XML data in
3290 SOAP encoding is not permitted. The only attributes permitted are the standard
3291 XSD attributes, SOAP encoding attributes (such as for arrays), and id-ref.
3292 
3293 For example, the following directives in the gSOAP header file for soapcpp2
3294 declare that `DBupdate` is a SOAP RPC encoding service method:
3295 
3296 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
3297  //gsoap ns service namespace: urn:DB
3298  //gsoap ns service method-protocol: DBupdate SOAP
3299  //gsoap ns service method-style: DBupdate rpc
3300  //gsoap ns service method-encoding: DBupdate encoded
3301  int ns__DBupdate(...);
3302 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3303 
3304 The XML payload has a SOAP envelope, optional SOAP header, and a SOAP body with
3305 an encodingStyle attribute for SOAP 1.1 encoding and an element representing the
3306 operation with parameters that are SOAP 1.1 encoded:
3307 
3308  <SOAP-ENV:Envelope
3309  xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
3310  xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"
3311  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3312  xmlns:xsd="http://www.w3.org/2001/XMLSchema"
3313  xmlsn:ns="urn:DB">
3314  <SOAP-ENV:Body SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
3315  <ns:DBupdate>
3316  <records SOAP-ENC:arrayType="ns:record[3]">
3317  <item>
3318  <name href="#_1"/>
3319  <SSN>1234567890</SSN>
3320  </item>
3321  <item>
3322  <name>Jane</name>
3323  <SSN>1987654320</SSN>
3324  </item>
3325  <item>
3326  <name href="#_1"/>
3327  <SSN>2345678901</SSN>
3328  </item>
3329  </records>
3330  </ns:DBupdate>
3331  <id id="_1" xsi:type="xsd:string">Joe</id>
3332  </SOAP-ENV:Body>
3333  </SOAP-ENV:Envelope>
3334 
3335 Note that the name "Joe" is shared by two records and the string is referenced
3336 by SOAP 1.1 href and id attributes.
3337 
3338 While gSOAP only introduces multi-referenced elements in the payload when they
3339 are actually multi-referenced in the data graph, other SOAP applications may
3340 render multi-referenced elements more aggressively. The example could also be
3341 rendered as:
3342 
3343  <SOAP-ENV:Envelope
3344  xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
3345  xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"
3346  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3347  xmlns:xsd="http://www.w3.org/2001/XMLSchema"
3348  xmlsn:ns="urn:DB">
3349  <SOAP-ENV:Body SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
3350  <ns:DBupdate>
3351  <records SOAP-ENC:arrayType="ns:record[3]">
3352  <item href="#id1"/>
3353  <item href="#id2"/>
3354  <item href="#id3"/>
3355  </records>
3356  </ns:DBupdate>
3357  <id id="id1" xsi:type="ns:record">
3358  <name href="#id4"/>
3359  <SSN>1234567890</SSN>
3360  </id>
3361  <id id="id2" xsi:type="ns:record">
3362  <name href="#id5"/>
3363  <SSN>1987654320</SSN>
3364  </id>
3365  <id id="id3" xsi:type="ns:record">
3366  <name href="#id4"/>
3367  <SSN>2345678901</SSN>
3368  </id>
3369  <id id="id4" xsi:type="xsd:string">Joe</id>
3370  <id id="id5" xsi:type="xsd:string">Jane</id>
3371  </SOAP-ENV:Body>
3372  </SOAP-ENV:Envelope>
3373 
3374 SOAP 1.2 encoding is cleaner and produces more accurate XML encodings of data
3375 graphs by setting the id attribute on the element that is referenced:
3376 
3377  <SOAP-ENV:Envelope
3378  xmlns:SOAP-ENV="http://www.w3.org/2003/05/soap-envelope"
3379  xmlns:SOAP-ENC="http://www.w3.org/2003/05/soap-encoding"
3380  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3381  xmlns:xsd="http://www.w3.org/2001/XMLSchema"
3382  xmlsn:ns="urn:DB">
3383  <SOAP-ENV:Body>
3384  <ns:DBupdate SOAP-ENV:encodingStyle="http://www.w3.org/2003/05/soap-encoding">
3385  <records SOAP-ENC:itemType="ns:record" SOAP-ENC:arraySize="3">
3386  <item>
3387  <name SOAP-ENC:id="_1">Joe</name>
3388  <SSN>1234567890</SSN>
3389  </item>
3390  <item>
3391  <name>Jane</name>
3392  <SSN>1987654320</SSN>
3393  </item>
3394  <item>
3395  <name SOAP-ENC:ref="_1"/>
3396  <SSN>2345678901</SSN>
3397  </item>
3398  </records>
3399  </ns:DBupdate>
3400  </SOAP-ENV:Body>
3401  </SOAP-ENV:Envelope>
3402 
3403 @note Some SOAP 1.2 applications consider the namespace `SOAP-ENC` of
3404 `SOAP-ENC:id` and `SOAP-ENC:ref` optional. The gSOAP SOAP 1.2 encoding
3405 serialization follows the 2007 standard, while accepting unqualified id and
3406 ref attributes.
3407 
3408 To remove all rendered id-ref multi-referenced elements in gSOAP, use the
3409 `SOAP_XML_TREE` flag to initialize the gSOAP engine context.
3410 
3411 Some XML validation rules are turned off with SOAP encoding, because of the
3412 presence of additional attributes, such as id and ref/href, SOAP arrays with
3413 arbitrary element tags for array elements, and the occurrence of additional
3414 multi-ref elements in the SOAP 1.1 Body.
3415 
3416 The use of "literal" puts no restrictions on the XML in the SOAP Body. Full
3417 XML validation is possible, which can be enabled with the `SOAP_XML_STRICT`
3418 flag to initialize the gSOAP engine context. However, data graphs will be
3419 serialized as trees and cycles in the data will be cut from the XML rendition.
3420 
3421 SOAP 1.1 versus SOAP 1.2 {#soap}
3422 ------------------------
3423 
3424 There are two SOAP protocol versions: 1.1 and 1.2. The gSOAP tools can switch
3425 between the two versions seamlessly. You can declare the default SOAP version
3426 for a service operation as follows:
3427 
3428 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
3429  //gsoap ns service method-protocol: DBupdate SOAP1.2
3430 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3431 
3432 The gSOAP soapcpp2 auto-generates client and server code. At the client side,
3433 this operation sends data with SOAP 1.2 but accepts responses also in SOAP 1.1.
3434 At the server side, this operation accepts requests in SOAP 1.1 and 1.2 and
3435 will return responses in the same SOAP version.
3436 
3437 As we discussed in the previous section, the SOAP 1.2 protocol has a cleaner
3438 multi-referenced element serialization format that greatly enhances the
3439 accuracy of data graph serialization with SOAP RPC encoding and is therefore
3440 recommended.
3441 
3442 The SOAP 1.2 protocol default can also be set by importing and loading
3443 `gsoap/import/soap12.h`:
3444 
3445 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
3446  #import "soap12.h"
3447 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3448 
3449 Non-SOAP XML serialization {#non-soap}
3450 --------------------------
3451 
3452 You can serialize data that is stored on the heap, on the stack (locals), and
3453 static data as long as the serializable (i.e. non-transient) members are
3454 properly initialized and pointers in the structures are either NULL or point to
3455 valid structures. Deserialized data is put on the heap and managed by the
3456 gSOAP engine context `struct soap`, see also [memory management](#memory).
3457 
3458 You can read and write XML directly to a file or stream with the serializing
3459 [operations on classes and structs](#toxsd9-13).
3460 
3461 To define and use XML Web service client and service operations, we can declare
3462 these operations in your gSOAP header file with the data binding interface for
3463 soapcpp2 as functions. The function are translated by soapcpp2 to client-side
3464 service invocation calls and server-side service operation dispatchers.
3465 
3466 The REST operations POST, GET, and PUT are declared with `//gsoap` directives
3467 in the gSOAP header file for soapcpp2. For example, a REST POST operation is
3468 declared as follows:
3469 
3470 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
3471  //gsoap ns service namespace: urn:DB
3472  //gsoap ns service method-protocol: DBupdate POST
3473  int ns__DBupdate(...);
3474 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3475 
3476 There is no SOAP Envelope and no SOAP Body in the payload for `DBupdate`. Also
3477 the XML serialization rules are identical to SOAP document/literal. The XML
3478 payload only has the operation name as an element with its parameters
3479 serialized as subelements:
3480 
3481  <ns:DBupdate xmln:ns="urn:DB" ...>
3482  ...
3483  </ns:DBupdate>
3484 
3485 To force id-ref serialization with REST similar to SOAP 1.2 multi-reference
3486 encoding, use the `SOAP_XML_GRAPH` flag to initialize the gSOAP engine context.
3487 The XML serialization includes id and ref attributes for multi-referenced
3488 elements as follows:
3489 
3490  <ns:DBupdate xmln:ns="urn:DB" ...>
3491  <records>
3492  <item>
3493  <name id="_1">Joe</name>
3494  <SSN>1234567890</SSN>
3495  </item>
3496  <item>
3497  <name>Jane</name>
3498  <SSN>1987654320</SSN>
3499  </item>
3500  <item>
3501  <name ref="_1"/>
3502  <SSN>2345678901</SSN>
3503  </item>
3504  </records>
3505  </ns:DBupdate>
3506 
3507 Input and output {#io}
3508 ================
3509 
3510 Reading and writing XML from/to files, streams and string buffers is done via
3511 the managing context by setting one of the following context members that
3512 control IO sources and sinks:
3513 
3514 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
3515  soap->recvfd = fd; // an int file descriptor to read from (0 by default)
3516  soap->sendfd = fd; // an int file descriptor to write to (1 by default)
3517  soap->is = &is; // C++ only: a std::istream is object to read from
3518  soap->os = &os; // C++ only: a std::ostream os object to write to
3519  soap->is = cs; // C only: a const char* string to read from (soap->is will advance)
3520  soap->os = &cs; // C only: pointer to a const char*, will be set to point to the string output
3521 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3522 
3523 Normally, all of these context members are NULL, which is required to send and
3524 receive data over sockets by gSOAP clients and servers. Therefore, if you set
3525 any of these context members in a client or server application then you MUST
3526 reset them to NULL to ensure that socket communications are not blocked.
3527 
3528 Note: the use of `soap->is` and `soap->os` in C requires gSOAP 2.8.28 or later.
3529 
3530 In the following sections, we present more details on how to read and write to
3531 files and streams, and use string buffers as sources and sinks for XML data.
3532 
3533 In addition, you can set IO callback functions to handle IO at a lower level.
3534 
3535 For more details, see the [gSOAP user guide.](http://www.genivia.com/doc/soapdoc2.html)
3536 
3537 Reading and writing from/to files and streams {#io1}
3538 ---------------------------------------------
3539 
3540 The default IO is standard input and output. Other sources and sinks (those
3541 listed above) will be used until you (re)set them. For example with file-based
3542 input and output:
3543 
3544 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
3545  FILE *fp = fopen("record.xml", "r");
3546  if (fp != NULL)
3547  {
3548  soap->recvfd = fileno(fp); // get file descriptor of file to read from
3549  if (soap_read_ns__record(soap, &pers1))
3550  ... // handle IO error
3551  fclose(fp);
3552  soap->recvfd = 0; // read from stdin, or -1 to block reading
3553  }
3554 
3555  FILE *fp = fopen("record.xml", "w");
3556  if (fp != NULL)
3557  {
3558  soap->sendfd = fileno(fp); // get file descriptor of file to write to
3559  if (soap_write_ns__record(soap, &pers1))
3560  ... // handle IO error
3561  fclose(fp);
3562  soap->sendfd = 1; // write to stdout, or -1 to block writing
3563  }
3564 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3565 
3566 Similar code with streams in C++:
3567 
3568 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
3569  #include <fstream>
3570 
3571  std::fstream fs;
3572  fs.open("record.xml", std::ios::in);
3573  if (fs)
3574  {
3575  soap->is = &fs;
3576  if (soap_read__ns__record(soap, &pers1))
3577  ... // handle IO error
3578  fs.close();
3579  soap->is = NULL;
3580  }
3581 
3582  fs.open("record.xml", std::ios::out);
3583  if (fs)
3584  {
3585  soap->os = &fs;
3586  if (soap_write__ns__record(soap, &pers1))
3587  ... // handle IO error
3588  fs.close();
3589  soap->os = NULL;
3590  }
3591 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3592 
3593 Reading and writing from/to string buffers {#io2}
3594 ------------------------------------------
3595 
3596 For C++ we recommend to use `std::stringstream` objects from `<sstream>` as
3597 illustrated in the following example:
3598 
3599 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
3600  #include <sstream>
3601 
3602  std::stringstream ss;
3603  ss.str("..."); // XML to parse
3604  soap->is = &ss;
3605  if (soap_read__ns__record(soap, &pers1))
3606  ... // handle IO error
3607  soap->is = NULL;
3608 
3609  soap->os = &ss;
3610  if (soap_write__ns__record(soap, &pers1))
3611  ... // handle IO error
3612  soap->os = NULL;
3613  std::string s = ss.str(); // string with XML
3614 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3615 
3616 For C we can use `soap->is` and `soap->os` to point to strings of XML content
3617 as follows (this requires gSOAP 2.8.28 or later):
3618 
3619 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
3620  soap->is = "..."; // XML to parse
3621  if (soap_read__ns__record(soap, &pers1))
3622  ... // handle IO error
3623  soap->is = NULL;
3624 
3625  const char *cs = NULL;
3626  soap->os = &cs;
3627  if (soap_write__ns__record(soap, &pers1))
3628  ... // handle IO error
3629  soap->os = NULL;
3630  ... = cs; // string with XML (do not free(cs): managed by the context and freed with soap_end())
3631 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3632 
3633 Note that `soap->os` is a pointer to a `const char*` string. The pointer is
3634 set by the managing context to point to the XML data that is stored on the
3635 context-managed heap.
3636 
3637 For earlier gSOAP versions we recommend to use IO callbacks `soap->frecv` and
3638 `soap->fsend`, see the [gSOAP user guide.](http://www.genivia.com/doc/soapdoc2.html)
3639 
3640 Memory management {#memory}
3641 =================
3642 
3643 Memory management with the `soap` context enables us to allocate data in
3644 context-managed heap space that can be collectively deleted. All deserialized
3645 data is placed on the context-managed heap by the gSOAP engine.
3646 
3647 Memory management in C {#memory1}
3648 ----------------------
3649 
3650 In C (wsdl2h option `-c` and soapcpp2 option `-c`), the gSOAP engine allocates
3651 data on a context-managed heap with:
3652 
3653 - `void *soap_malloc(struct soap*, size_t len)`.
3654 
3655 You can also make shallow copies of data with `soap_memdup` that uses
3656 `soap_malloc` and a safe version of `memcpy` to copy a chunk of data `src` with
3657 length `len` to the context-managed heap:
3658 
3659 - `void *soap_memdup(struct soap*, const void *src, size_t len)`
3660 
3661 This function returns a pointer to the copy. This function requires gSOAP
3662 2.8.27 or later.
3663 
3664 The `soap_malloc` function is a wrapper around `malloc`, but which also permits
3665 the `struct soap` context to track all heap allocations for collective deletion
3666 with `soap_end(soap)`:
3667 
3668 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
3669  #include "soapH.h"
3670  #include "ns.nsmap"
3671  ...
3672  struct soap *soap = soap_new(); // new context
3673  ...
3674  struct ns__record *record = soap_malloc(soap, sizeof(struct ns__record));
3675  soap_default_ns__record(soap, record); // auto-generated struct initializer
3676  ...
3677  soap_destroy(soap); // only for C++, see section on C++ below
3678  soap_end(soap); // delete record and all other heap allocations
3679  soap_free(soap); // delete context
3680 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3681 
3682 The soapcpp2 auto-generated deserializers in C use `soap_malloc` to allocate
3683 and populate deserialized structures, which are managed by the context for
3684 collective deletion.
3685 
3686 To make `char*` and `wchar_t*` string copies to the context-managed heap, we
3687 can use the functions:
3688 
3689 - `char *soap_strdup(struct soap*, const char *str)` and
3690 - `wchar_t *soap_wstrdup(struct soap*, const wchar_t *wstr)`.
3691 
3692 If your C compiler supports `typeof` then you can use the following macro to
3693 simplify the managed heap allocation and initialization of primitive values:
3694 
3695 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
3696  #define soap_assign(soap, lhs, rhs) (*(lhs = (typeof(lhs))soap_malloc(soap, sizeof(*lhs))) = rhs)
3697 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3698 
3699 Pointers to primitive values are often used for optional members. For example,
3700 assume we have the following struct:
3701 
3702 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
3703  struct ns__record
3704  {
3705  const char *name; // required name
3706  uint64_t *SSN; // optional SSN
3707  struct ns__record *spouse; // optional spouse
3708  };
3709 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3710 
3711 Use `soap_assign` to create a SSN value on the managed heap:
3712 
3713 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
3714  struct soap *soap = soap_new(); // new context
3715  ...
3716  struct ns__record *record = soap_malloc(soap, sizeof(struct ns__record));
3717  soap_default_ns__record(soap, record);
3718  record->name = soap_strdup(soap, "Joe");
3719  soap_assign(soap, record->SSN, 1234567890LL);
3720  ...
3721  soap_end(soap); // delete managed soap_malloc'ed heap data
3722  soap_free(soap); // delete context
3723 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3724 
3725 Without the `soap_assign` macro, you will need two lines of code, one to
3726 allocate and one to assign (you should also use this if your system can run out
3727 of memory):
3728 
3729 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
3730  assert((record->SSN = (uint64_t*)soap_malloc(soap, sizeof(utint64_t))) != NULL);
3731  *record->SSN = 1234567890LL;
3732 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3733 
3734 The gSOAP serializer can serialize any heap, stack, or static allocated data.
3735 So we can also create a new record as follows:
3736 
3737 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
3738  struct soap *soap = soap_new(); // new context
3739  ...
3740  struct ns__record *record = soap_malloc(soap, sizeof(struct ns__record));
3741  static uint64_t SSN = 1234567890LL;
3742  soap_default_ns__record(soap, record);
3743  record->name = "Joe";
3744  record->SSN = &SSN; // safe to use static values: the value of record->SSN is never changed by gSOAP
3745  ...
3746  soap_end(soap); // delete managed soap_malloc'ed heap data
3747  soap_free(soap); // delete context
3748 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3749 
3750 Use the soapcpp2 auto-generated `soap_dup_T` functions to duplicate data into
3751 another context (this requires soapcpp2 option `-Ec` to generate), here shown
3752 for C with the second argument `dst` NULL because we want to allocate a new
3753 managed structure:
3754 
3755 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
3756  struct soap *other_soap = soap_new(); // another context
3757  struct ns__record *other_record = soap_dup_ns__record(other_soap, NULL, record);
3758  ...
3759  soap_destroy(other_soap); // only for C++, see section on C++ below
3760  soap_end(other_soap); // delete other_record and all of its deep data
3761  soap_free(other_soap); // delete context
3762 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3763 
3764 Note that the only reason to use another context and not to use the primary
3765 context is when the primary context must be destroyed together with all of the
3766 objects it manages while some of the objects must be kept alive. If the objects
3767 that are kept alive contain deep cycles then this is the only option we have,
3768 because deep copy with a managing context detects and preserves these
3769 cycles unless the `SOAP_XML_TREE` flag is used with the context:
3770 
3771 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
3772  struct soap *other_soap = soap_new1(SOAP_XML_TREE); // another context
3773  struct ns__record *other_record = soap_dup_ns__record(other_soap, NULL, record);
3774 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3775 
3776 The resulting deep copy will be a full copy of the source data structure as a
3777 tree without co-referenced data (i.e. no digraph) and without cycles. Cycles
3778 are pruned and (one of the) pointers that forms a cycle is repaced by NULL.
3779 
3780 You can also deep copy into unmanaged space and use the auto-generated
3781 `soap_del_T()` function (requires soapcpp2 option `-Ed` to generate) to delete
3782 it later, but you MUST NOT do this for any data that has deep cycles in its
3783 runtime data structure:
3784 
3785 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
3786  struct ns__record *other_record = soap_dup_ns__record(NULL, NULL, record);
3787  ...
3788  soap_del_ns__record(other_record); // deep delete record data members
3789  free(other_record); // delete the record
3790 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3791 
3792 Cycles in the data structure will lead to non-termination when making unmanaged
3793 deep copies. Consider for example:
3794 
3795 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
3796  struct ns__record
3797  {
3798  const char *name; // required name
3799  uint64_t SSN; // required SSN
3800  struct ns__record *spouse; // optional spouse
3801  };
3802 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3803 
3804 The code to populate a structure with a mutual spouse relationship:
3805 
3806 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
3807  struct soap *soap = soap_new();
3808  ...
3809  struct ns__record pers1, pers2;
3810  soap_default_ns__record(soap, &pers1);
3811  soap_default_ns__record(soap, &pers2);
3812  pers1.name = "Joe"; // OK to serialize static data
3813  pers1.SSN = 1234567890;
3814  pers1.spouse = &pers2;
3815  pers2.name = soap_strdup(soap, "Jane"); // allocates and copies a string
3816  pers2.SSN = 1987654320;
3817  pers2.spouse = &pers1;
3818  ...
3819  struct ns__record *pers3 = soap_dup_ns__record(NULL, NULL, &pers1); // BAD
3820  struct ns__record *pers4 = soap_dup_ns__record(soap, NULL, &pers1); // OK
3821  soap_set_mode(soap, SOAP_XML_TREE);
3822  struct ns__record *pers5 = soap_dup_ns__record(soap, NULL, &pers1); // OK
3823 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3824 
3825 As we can see, the gSOAP serializer can serialize any heap, stack, or static
3826 allocated data, such as in the code above. So we can serialize the
3827 stack-allocated `pers1` record as follows:
3828 
3829 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
3830  FILE *fp = fopen("record.xml", "w");
3831  if (fp != NULL)
3832  {
3833  soap->sendfd = fileno(fp); // file descriptor to write to
3834  soap_set_mode(soap, SOAP_XML_GRAPH); // support id-ref w/o requiring SOAP
3835  soap_clr_mode(soap, SOAP_XML_TREE); // if set, clear
3836  soap_write_ns__record(soap, &pers1);
3837  fclose(fp);
3838  soap->sendfd = -1; // block further writing
3839  }
3840 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3841 
3842 which produces an XML document record.xml that is similar to:
3843 
3844  <ns:record xmlns:ns="urn:types" id="Joe">
3845  <name>Joe</name>
3846  <SSN>1234567890</SSN>
3847  <spouse id="Jane">
3848  <name>Jane</name>
3849  <SSN>1987654320</SSN>
3850  <spouse ref="#Joe"/>
3851  </spouse>
3852  </ns:record>
3853 
3854 Deserialization of an XML document with a SOAP 1.1/1.2 encoded id-ref graph
3855 leads to the same non-termination problem when we later try to copy the data
3856 into unmanaged space:
3857 
3858 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
3859  struct soap *soap = soap_new1(SOAP_XML_GRAPH); // support id-ref w/o SOAP
3860  ...
3861  struct ns__record pers1;
3862  FILE *fp = fopen("record.xml", "r");
3863  if (fp != NULL)
3864  {
3865  soap->recvfd = fileno(fp);
3866  if (soap_read_ns__record(soap, &pers1))
3867  ... // handle IO error
3868  fclose(fp);
3869  soap->recvfd = -1; // blocks further reading
3870  }
3871  ...
3872  struct ns__record *pers3 = soap_dup_ns__record(NULL, NULL, &pers1); // BAD
3873  struct ns__record *pers4 = soap_dup_ns__record(soap, NULL, &pers1); // OK
3874  soap_set_mode(soap, SOAP_XML_TREE);
3875  struct ns__record *pers5 = soap_dup_ns__record(soap, NULL, &pers1); // OK
3876 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3877 
3878 Copying data with `soap_dup_T(soap)` into managed space is always safe. Copying
3879 into unmanaged space requires diligence. But deleting unmanaged data is easy
3880 with `soap_del_T()`.
3881 
3882 You can also use `soap_del_T()` to delete structures that you created in C, but
3883 only if these structures are created with `malloc` and do NOT contain pointers
3884 to stack and static data.
3885 
3886 Memory management in C++ {#memory2}
3887 ------------------------
3888 
3889 In C++, the gSOAP engine allocates data on a managed heap using a combination
3890 of `void *soap_malloc(struct soap*, size_t len)` and `soap_new_T()`, where `T`
3891 is the name of a class, struct, or class template (container or smart pointer).
3892 Heap allocation is tracked by the `struct soap` context for collective
3893 deletion with `soap_destroy(soap)` and `soap_end(soap)`.
3894 
3895 Only structs, classes, and class templates are allocated with `new` via
3896 `soap_new_T(struct soap*)` and mass-deleted with `soap_destroy(soap)`.
3897 
3898 There are four variations of `soap_new_T` for class/struct/template type `T`
3899 that soapcpp2 auto-generates to create instances on a context-managed heap:
3900 
3901 - `T * soap_new_T(struct soap*)` returns a new instance of `T` with default data
3902  member initializations that are set with the soapcpp2 auto-generated `void
3903  T::soap_default(struct soap*)` method), but ONLY IF the soapcpp2
3904  auto-generated default constructor is used that invokes `soap_default()` and
3905  was not replaced by a user-defined default constructor.
3906 
3907 - `T * soap_new_T(struct soap*, int n)` returns an array of `n` new instances of
3908  `T`. Similar to the above, instances are initialized.
3909 
3910 - `T * soap_new_req_T(struct soap*, ...)` returns a new instance of `T` and sets
3911  the required data members to the values specified in `...`. The required data
3912  members are those with nonzero minOccurs, see the subsections on
3913  [(smart) pointer members and their occurrence constraints](#toxsd9-8) and
3914  [container members and their occurrence constraints](#toxsd9-9).
3915 
3916 - `T * soap_new_set_T(struct soap*, ...)` returns a new instance of `T` and sets
3917  the public/serializable data members to the values specified in `...`.
3918 
3919 The above functions can be invoked with a NULL `soap` context, but you are
3920 responsible to use `delete T` to remove this instance from the unmanaged heap.
3921 
3922 For example, to allocate a managed `std::string` you can use:
3923 
3924 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
3925  std::string *s = soap_new_std__string(soap);
3926 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3927 
3928 Primitive types and arrays of these are allocated with `soap_malloc` by the
3929 gSOAP engine. As we stated above, all types except for classes, structs, class
3930 templates (containers and smart pointers) are allocated with `soap_malloc` for
3931 reasons of efficiency.
3932 
3933 You can use a C++ template to simplify the managed allocation and initialization
3934 of primitive values as follows (this is for primitive types only, because
3935 structs and classes are allocated with `soap_new_T`):
3936 
3937 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
3938  template<class T>
3939  T * soap_make(struct soap *soap, T val)
3940  {
3941  T *p = (T*)soap_malloc(soap, sizeof(T));
3942  if (p) // out of memory? Can also guard with assert(p != NULL) or throw an error
3943  *p = val;
3944  return p;
3945  }
3946 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3947 
3948 For example, assuming we have the following class:
3949 
3950 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
3951  class ns__record
3952  {
3953  public:
3954  std::string name; // required name
3955  uint64_t *SSN; // optional SSN
3956  ns__record *spouse; // optional spouse
3957  };
3958 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3959 
3960 You can instantiate a record by using the auto-generated
3961 `soap_new_set_ns__record` and use `soap_make` to create a SSN value on the
3962 managed heap:
3963 
3964 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
3965  soap *soap = soap_new(); // new context
3966  ...
3967  ns__record *record = soap_new_set_ns__record(
3968  soap,
3969  "Joe",
3970  soap_make<uint64_t>(soap, 1234567890LL),
3971  NULL);
3972  ...
3973  soap_destroy(soap); // delete record and all other managed instances
3974  soap_end(soap); // delete managed soap_malloc'ed heap data
3975  soap_free(soap); // delete context
3976 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3977 
3978 Note however that the gSOAP serializer can serialize any heap, stack, or static
3979 allocated data. So we can also create a new record as follows:
3980 
3981 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
3982  uint64_t SSN = 1234567890LL;
3983  ns__record *record = soap_new_set_ns__record(soap, "Joe", &SSN, NULL);
3984 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3985 
3986 which will be fine to serialize this record as long as the local `SSN`
3987 stack-allocated value remains in scope when invoking the serializer and/or
3988 using `record`. It does not matter if `soap_destroy` and `soap_end` are called
3989 beyond the scope of `SSN`.
3990 
3991 To facilitate class methods to access the managing context, we can add a soap
3992 context pointer to a class/struct:
3993 
3994 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
3995  class ns__record
3996  {
3997  ...
3998  void create_more(); // needs a context to create more internal data
3999  protected:
4000  struct soap *soap; // the context that manages this instance, or NULL
4001  };
4002 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4003 
4004 The context is set when invoking `soap_new_T` (and similar) with a non-NULL
4005 context argument.
4006 
4007 Use the soapcpp2 auto-generated `soap_dup_T` functions to duplicate data into
4008 another context (this requires soapcpp2 option `-Ec` to generate), here shown
4009 for C++ with the second argument `dst` NULL to allocate a new managed object:
4010 
4011 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
4012  soap *other_soap = soap_new(); // another context
4013  ns__record *other_record = soap_dup_ns__record(other_soap, NULL, record);
4014  ...
4015  soap_destroy(other_soap); // delete record and other managed instances
4016  soap_end(other_soap); // delete other data (the SSNs on the heap)
4017  soap_free(other_soap); // delete context
4018 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4019 
4020 To duplicate base and derived instances when a base class pointer or reference
4021 is provided, use the auto-generated method `T * T::soap_dup(struct soap*)`:
4022 
4023 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
4024  soap *other_soap = soap_new(); // another context
4025  ns__record *other_record = record->soap_dup(other_soap);
4026  ...
4027  soap_destroy(other_soap); // delete record and other managed instances
4028  soap_end(other_soap); // delete other data (the SSNs on the heap)
4029  soap_free(other_soap); // delete context
4030 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4031 
4032 Note that the only reason to use another context and not to use the primary
4033 context is when the primary context must be destroyed together with all of the
4034 objects it manages while some of the objects must be kept alive. If the objects
4035 that are kept alive contain deep cycles then this is the only option we have,
4036 because deep copy with a managing context detects and preserves these
4037 cycles unless the `SOAP_XML_TREE` flag is used with the context:
4038 
4039 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
4040  soap *other_soap = soap_new1(SOAP_XML_TREE); // another context
4041  ns__record *other_record = record->soap_dup(other_soap); // deep tree copy
4042 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4043 
4044 The resulting deep copy will be a full copy of the source data structure as a
4045 tree without co-referenced data (i.e. no digraph) and without cycles. Cycles
4046 are pruned and (one of the) pointers that forms a cycle is repaced by NULL.
4047 
4048 You can also deep copy into unmanaged space and use the auto-generated
4049 `soap_del_T()` function or the `T::soap_del()` method (requires soapcpp2 option
4050 `-Ed` to generate) to delete it later, but we MUST NOT do this for any data
4051 that has deep cycles in its runtime data structure graph:
4052 
4053 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
4054  ns__record *other_record = record->soap_dup(NULL);
4055  ...
4056  other_record->soap_del(); // deep delete record data members
4057  delete other_record; // delete the record
4058 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4059 
4060 Cycles in the data structure will lead to non-termination when making unmanaged
4061 deep copies. Consider for example:
4062 
4063 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
4064  class ns__record
4065  {
4066  const char *name; // required name
4067  uint64_t SSN; // required SSN
4068  ns__record *spouse; // optional spouse
4069  };
4070 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4071 
4072 The code to populate a structure with a mutual spouse relationship:
4073 
4074 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
4075  soap *soap = soap_new();
4076  ...
4077  ns__record pers1, pers2;
4078  pers1.name = "Joe";
4079  pers1.SSN = 1234567890;
4080  pers1.spouse = &pers2;
4081  pers2.name = "Jane";
4082  pers2.SSN = 1987654320;
4083  pers2.spouse = &pers1;
4084  ...
4085  ns__record *pers3 = soap_dup_ns__record(NULL, NULL, &pers1); // BAD
4086  ns__record *pers4 = soap_dup_ns__record(soap, NULL, &pers1); // OK
4087  soap_set_mode(soap, SOAP_XML_TREE);
4088  ns__record *pers5 = soap_dup_ns__record(soap, NULL, &pers1); // OK
4089 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4090 
4091 Note that the gSOAP serializer can serialize any heap, stack, or static
4092 allocated data, such as in the code above. So we can serialize the
4093 stack-allocated `pers1` record as follows:
4094 
4095 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
4096  FILE *fp = fopen("record.xml", "w");
4097  if (fp != NULL)
4098  {
4099  soap->sendfd = fileno(fp); // file descriptor to write to
4100  soap_set_mode(soap, SOAP_XML_GRAPH); // support id-ref w/o requiring SOAP
4101  soap_clr_mode(soap, SOAP_XML_TREE); // if set, clear
4102  if (soap_write_ns__record(soap, &pers1))
4103  ... // handle IO error
4104  fclose(fp);
4105  soap->sendfd = -1; // block further writing
4106  }
4107 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4108 
4109 which produces an XML document record.xml that is similar to:
4110 
4111  <ns:record xmlns:ns="urn:types" id="Joe">
4112  <name>Joe</name>
4113  <SSN>1234567890</SSN>
4114  <spouse id="Jane">
4115  <name>Jane</name>
4116  <SSN>1987654320</SSN>
4117  <spouse ref="#Joe"/>
4118  </spouse>
4119  </ns:record>
4120 
4121 Deserialization of an XML document with a SOAP 1.1/1.2 encoded id-ref graph
4122 leads to the same non-termination problem when we later try to copy the data
4123 into unmanaged space:
4124 
4125 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
4126  soap *soap = soap_new1(SOAP_XML_GRAPH); // support id-ref w/o SOAP
4127  ...
4128  ns__record pers1;
4129  FILE *fp = fopen("record.xml", "r");
4130  if (fp != NULL)
4131  {
4132  soap->recvfd = fileno(fp); // file descriptor to read from
4133  if (soap_read_ns__record(soap, &pers1))
4134  ... // handle IO error
4135  fclose(fp);
4136  soap->recvfd = -1; // block further reading
4137  }
4138  ...
4139  ns__record *pers3 = soap_dup_ns__record(NULL, NULL, &pers1); // BAD
4140  ns__record *pers4 = soap_dup_ns__record(soap, NULL, &pers1); // OK
4141  soap_set_mode(soap, SOAP_XML_TREE);
4142  ns__record *pers5 = soap_dup_ns__record(soap, NULL, &pers1); // OK
4143 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4144 
4145 Copying data with `soap_dup_T(soap)` into managed space is always safe. Copying
4146 into unmanaged space requires diligence. But deleting unmanaged data is easy
4147 with `soap_del_T()`.
4148 
4149 You can also use `soap_del_T()` to delete structures in C++, but only if these
4150 structures are created with `new` (and `new []` for arrays when applicable) for
4151 classes, structs, and class templates and with `malloc` for anything else, and
4152 the structures do NOT contain pointers to stack and static data.
4153 
4154 Features and limitations {#features}
4155 ========================
4156 
4157 In general, to use the generated code:
4158 
4159 - Make sure to `#include "soapH.h"` in your code and also define a namespace
4160  table or `#include "ns.nsmap"` with the generated table, where `ns` is the
4161  namespace prefix for services.
4162 
4163 - Use soapcpp2 option -j (C++ only) to generate C++ proxy and service objects.
4164  The auto-generated files include documented inferfaces. Compile with
4165  soapC.cpp and link with -lgsoap++, or alternatively compile stdsoap2.cpp.
4166 
4167 - Without soapcpp2 option -j: client-side uses the auto-generated
4168  soapClient.cpp and soapC.cpp (or C versions of those). Compile and link with
4169  -lgsoap++ (-lgsoap for C), or alternatively compile stdsoap2.cpp
4170  (stdsoap2.c for C).
4171 
4172 - Without soapcpp2 option -j: server-side uses the auto-generated
4173  soapServer.cpp and soapC.cpp (or C versions of those). Compile and link with
4174  -lgsoap++ (-lgsoap for C), or alternatively compile stdsoap2.cpp (stdsoap2.c
4175  for C).
4176 
4177 - Use `soap_new()` or `soap_new1(int flags)` to allocate and initialize a
4178  heap-allocated context with or without flags. Delete this context with
4179  `soap_free(struct soap*)`, but only after `soap_destroy(struct soap*)` and
4180  `soap_end(struct soap*)`.
4181 
4182 - Use `soap_init(struct *soap)` or `soap_init1(struct soap*, int flags)` to
4183  initialize a stack-allocated context with or without flags. End the use of
4184  this context with `soap_done(struct soap*)`, but only after
4185  `soap_destroy(struct soap*)` and `soap_end(struct soap*)`.
4186 
4187 There are several context initialization flags and context mode flags to
4188 control XML serialization at runtime:
4189 
4190 - `SOAP_C_UTFSTRING`: enables all `std::string` and `char*` strings to
4191  contain UTF-8 content. This option is recommended.
4192 
4193 - `SOAP_XML_STRICT`: strictly validates XML while deserializing. Should not be
4194  used together with SOAP 1.1/1.2 encoding style of messaging. Use soapcpp2
4195  option `-s` to hard code `SOAP_XML_STRICT` in the generated serializers. Not
4196  recommended with SOAP 1.1/1.2 encoding style messaging.
4197 
4198 - `SOAP_XML_INDENT`: produces indented XML.
4199 
4200 - `SOAP_XML_CANONICAL`: c14n canonocalization, removes unused `xmlns` bindings
4201  and adds them to appropriate places by applying c14n normalization rules.
4202  Should not be used together with SOAP 1.1/1.2 encoding style messaging.
4203 
4204 - `SOAP_XML_TREE`: write tree XML without id-ref, while pruning data structure
4205  cycles to prevent nontermination of the serializer for cyclic structures.
4206 
4207 - `SOAP_XML_GRAPH`: write graph (digraph and cyclic graphs with shared pointers
4208  to objects) using id-ref attributes. That is, XML with SOAP multi-ref
4209  encoded id-ref elements. This is a structure-preserving serialization format,
4210  because co-referenced data and also cyclic relations are accurately represented.
4211 
4212 - `SOAP_XML_DEFAULTNS`: uses xmlns default namespace declarations, assuming
4213  that the schema attribute form is "qualified" by default (be warned if it is
4214  not, since attributes in the null namespace will get bound to namespaces!).
4215 
4216 - `SOAP_XML_NOTYPE`: removes all `xsi:type` attribuation. This option is usually
4217  not needed unless the receiver rejects all `xsi:type` attributes. This option
4218  may affect the quality of the deserializer, which relies on `xsi:type`
4219  attributes to distinguish base class instances from derived class instances
4220  transported in the XML payloads.
4221 
4222 Additional notes with respect to the wsdl2h and soapcpp2 tools:
4223 
4224 - Nested classes, structs, and unions in a gSOAP header file are unnested by
4225  soapcpp2.
4226 
4227 - Use `#import "file.h"` instead of `#include` to import other header files in
4228  a gSOAP header file for soapcpp2. The `#include`, `#define`, and `#pragma`
4229  are accepted by soapcpp2, but are moved to the very start of the generated
4230  code for the C/C++ compiler to include before all generated definitions.
4231  Often it is useful to add an `#include` with a [volatile type](#toxsd9-2)
4232  that includes the actual type declaration, and to ensure transient types are
4233  declared when these are used in a data binding interface declared in a gSOAP
4234  header file for soapcpp2.
4235 
4236 - To remove any SOAP-specific bindings, use soapcpp2 option `-0`.
4237 
4238 - A gSOAP header file for soapcpp2 should not include any code statements, only
4239  data type declarations. This includes constructor initialization lists that are
4240  not permitted. Use member initializations instead.
4241 
4242 - C++ namespaces are supported. Use wsdl2h option `-qname`. Or add a `namespace
4243  name { ... }` to the header file, but the `{ ... }` MUST cover the entire
4244  header file content from begin to end.
4245 
4246 - Optional XML DOM support can be used to store mixed content or literal XML
4247  content. Otherwise, mixed content may be lost. Use wsdl2h option `-d` for
4248  XML DOM support and compile and link with `dom.c` or `dom.cpp`. For details,
4249  see [XML DOM and XPath](http://www.genivia.com/doc/dom/html).
4250 
4251 Removing SOAP namespaces from XML payloads {#nsmap}
4252 ==========================================
4253 
4254 The soapcpp2 tool generates a `.nsmap` file that includes two bindings for SOAP
4255 namespaces. We can remove all SOAP namespaces (and SOAP processing logic) with
4256 soapcpp2 option `-0` or by simply setting the two entries to NULL:
4257 
4258 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
4259  struct Namespace namespaces[] =
4260  {
4261  {"SOAP-ENV", NULL, NULL, NULL},
4262  {"SOAP-ENC", NULL, NULL, NULL},
4263  ...
4264  };
4265 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4266 
4267 Note that once the `.nsmap` is generated, you can copy-paste the content into
4268 your project code. However, if we rerun wsdl2h on updated WSDL/XSD files or
4269 `typemap.dat` declarations then we need to use the updated table.
4270 
4271 In cases that no XML namespaces are used at all, for example with
4272 [XML-RPC](http://www.genivia.com/doc/xml-rpc-json/html), you may use an empty
4273 namespace table:
4274 
4275 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
4276  struct Namespace namespaces[] = {{NULL,NULL,NULL,NULL}};
4277 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4278 
4279 However, beware that any built-in xsi attributes that are rendered will lack
4280 the proper namespace binding. At least we suggest to use `SOAP_XML_NOTYPE` for
4281 this reason.
4282 
4283 Examples {#examples}
4284 ========
4285 
4286 Select the project files below to peruse the source code examples.
4287 
4288 Source files
4289 ------------
4290 
4291 - `address.xsd` Address book schema
4292 - `address.cpp` Address book app (reads/writes address.xml file)
4293 - `addresstypemap.dat` Schema namespace prefix name preference for wsdl2h
4294 - `graph.h` Graph data binding (tree, digraph, cyclic graph)
4295 - `graph.cpp` Test graph serialization as tree, digraph, and cyclic
4296 
4297 Generated files
4298 ---------------
4299 
4300 - `address.h` gSOAP-specific data binding definitions from address.xsd
4301 - `addressStub.h` C++ data binding definitions
4302 - `addressH.h` Serializers
4303 - `addressC.cpp` Serializers
4304 - `address.xml` Address book data generated by address app
4305 - `graphStub.h` C++ data binding definitions
4306 - `graphH.h` Serializers
4307 - `graphC.cpp` Serializers
4308 - `g.xsd` XSD schema with `g:Graph` complexType
4309 - `g.nsmap` xmlns bindings namespace mapping table
4310 
4311 Build steps
4312 -----------
4313 
4314 Building the AddressBook example:
4315 
4316  wsdl2h -g -t addresstypemap.dat address.xsd
4317  soapcpp2 -0 -CS -I../../import -p address address.h
4318  c++ -I../.. address.cpp addressC.cpp -o address -lgsoap++
4319 
4320 Option `-g` produces bindings for global (root) elements in addition to types.
4321 In this case the root element `a:address-book` is bound to `_a__address_book`.
4322 The complexType `a:address` is bound to class `a__address`, which is also the
4323 type of `_a__address_book`. This option is not required, but allows you to use
4324 global element tag names when referring to their serializers, instead of their
4325 type name. Option `-0` removes the SOAP protocol. Options `-C` and `-S`
4326 removes client and server code generation. Option `-p` renames the output
4327 `soap` files to `address` files.
4328 
4329 See the `address.cpp` implementation and [related pages](pages.html).
4330 
4331 The `addresstypemap.dat` file specifies the XML namespace prefix for the
4332 bindings:
4333 
4334  # Bind the address book schema namespace to prefix 'a'
4335 
4336  a = "urn:address-book-example"
4337 
4338  # By default the xsd:dateTime schema type is translated to time_t
4339  # To map xsd:dateTime to struct tm, enable the following line:
4340 
4341  # xsd__dateTime = #import "../../custom/struct_tm.h"
4342 
4343  # ... and compile/link with custom/struct_tm.c
4344 
4345 The DOB field is a `xsd:dateTime`, which is bound to `time_t` by default. To
4346 change this to `struct tm`, enable the import of the `xsd__dateTime` custom
4347 serializer by uncommenting the definition of `xsd__dateTime` in
4348 `addresstypemap.dat`. Then change `soap_dateTime2s` to `soap_xsd__dateTime2s`
4349 in the code.
4350 
4351 Building the graph serialization example:
4352 
4353  soapcpp2 -CS -I../../import -p graph graph.h
4354  c++ -I../.. graph.cpp graphC.cpp -o graph -lgsoap++
4355 
4356 To compile without using the `libgsoap++` library: simply compile
4357 `stdsoap2.cpp` together with the above.
4358 
4359 Usage
4360 -----
4361 
4362 To execute the AddressBook example:
4363 
4364  ./address
4365 
4366 To execute the Graph serialization example:
4367 
4368  ./graph
4369