Genivia Home Documentation
README.md Source File

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