Genivia Home Documentation
README.md Source File

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