2 XML Data Bindings {#mainpage}
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.
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
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
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.
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
35 The information in this document is applicable to gSOAP 2.8.26 and higher, which
36 supports C++11 features. However, C++11 is not required to use this material
37 and the examples included, unless we need smart pointers and scoped
38 enumerations. While most of the examples in this document are given in C++,
39 the concepts also apply to C with the exception of containers, smart pointers,
40 classes and their methods. None of these exceptions limit the use of the
41 gSOAP tools for C in any way.
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.
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
60 Mapping WSDL and XML schemas to C/C++ {#tocpp}
61 =====================================
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:
67 wsdl2h [options] -o file.h ... XSD and WSDL files ...
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.
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.
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.
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).
91 This covers all of the following standard XSD components with their optional
92 attributes and properties:
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 |
100 | complexType | name, abstract, mixed, defaultAttributesApply |
102 | choice | minOccurs, maxOccurs |
103 | sequence | minOccurs, maxOccurs |
104 | group | name, ref, minOccurs, maxOccurs |
105 | attributeGroup | name, ref |
106 | any | minOccurs, maxOccurs |
109 And also the following standard XSD directives are covered:
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 |
119 The XSD facets and their mappings to C/C++ are:
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
143 All primitive XSD types are supported, including but not limited to the
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`) |
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) |
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:
177 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
178 typedef std::string xsd__token; // C++
179 typedef char *xsd__token; // C (wsdl2h option -c)
180 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
182 This associates a compatible value space to the type with the appropriate XSD
183 type name used by the soapcpp2-generated serializers.
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.
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.
193 Using typemap.dat to customize data bindings {#typemap}
194 ============================================
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.
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
206 XML namespace bindings {#typemap1}
207 ----------------------
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.
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.
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
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.
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).
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.
242 XSD type bindings {#typemap2}
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:
248 prefix__type = declaration | use | ptruse
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).
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`:
266 xsd__duration = #import "custom/duration.h"
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.
273 To map `xsd:string` to `wchar_t*` wide strings:
275 xsd__string = | wchar_t* | wchar_t*
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>`.
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:
285 prefix__type = ... | use | ptruse
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
293 ns__base = ... | int __type_base; void*
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
300 Custom serializers for XSD types {#custom}
301 --------------------------------
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
307 xsd__duration = #import "custom/duration.h"
309 The `xsd__duration` type is an alias of `long long` (`LONG64` or `int64_t`).
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).
316 We will discuss the custom serializers that are available to you.
318 ### xsd:integer {#custom-1}
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`:
323 xsd__integer = #import "custom/int128.h"
325 The `xsd__integer` type is an alias of `__int128_t`.
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
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`:
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 ;
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`:
347 xsd__integer = typedef LONG64 xsd__integer;
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.
352 @see Section [numerical types](#toxsd5).
354 ### xsd:decimal {#custom-2}
356 The wsdl2h tool maps `xsd:decimal` to a string by default. To map `xsd:decimal` to
357 extended precision floating point:
359 xsd__decimal = #import "custom/long_double.h" | long double
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
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
369 xsd__decimal = #import "custom/float128.h"
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.
375 In the XML payload the special values `INF`, `-INF`, `NaN` represent plus or
376 minus infinity and not-a-number, respectively.
378 @see Section [numerical types](#toxsd5).
380 ### xsd:dateTime {#custom-3}
382 The wsdl2h tool maps `xsd:dateTime` to `time_t` by default.
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.
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`).
394 To map `xsd:dateTime` to `xsd__dateTime` which is an alias of `struct tm`:
396 xsd__dateTime = #import "custom/struct_tm.h"
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`
402 xsd__dateTime = #import "custom/struct_timeval.h"
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
408 xsd__dateTime = #import "custom/chrono_time_point.h"
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:
418 xsd__dateTime = | char*
420 @see Section [date and time types](#toxsd7).
422 ### xsd:date {#custom-4}
424 The wsdl2h tool maps `xsd:date` to a string by default. We can map `xsd:date` to
427 xsd__date = #import "custom/struct_tm_date.h"
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`).
434 @see Section [date and time types](#toxsd7).
436 ### xsd:time {#custom-5}
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
442 xsd__time = #import "custom/long_time.h"
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.
449 @see Section [date and time types](#toxsd7).
451 ### xsd:duration {#custom-6}
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:
457 xsd__duration = #import "custom/duration.h"
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).
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`.
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`:
471 xsd__duration = #import "custom/chrono_duration.h"
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).
476 Certain observations with respect to receiving durations in years and months
477 apply to both of these serializer decoders for `xsd:duration`.
479 @see Section [time duration types](#toxsd8).
481 Class/struct member additions {#typemap3}
482 -----------------------------
484 All generated classes and structs can be augmented with additional
485 members such as methods, constructors and destructors, and private members:
487 prefix__type = $ member-declaration
489 For example, we can add method declarations and private members to a class, say
490 `ns__record` as follows:
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
496 Note that method declarations cannot include any code, because soapcpp2's input
497 permits only type declarations, not code.
499 Replacing XSD types by equivalent alternatives {#typemap4}
500 ----------------------------------------------
502 Type replacements can be given to replace one type entirely with another given
505 prefix__type1 == prefix__type2
507 This replaces all `prefix__type1` by `prefix__type2` in the wsdl2h output.
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`).
514 The built-in typemap.dat variables $CONTAINER and $POINTER {#typemap5}
515 ----------------------------------------------------------
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:
521 $CONTAINER = std::list
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:
526 $POINTER = std::shared_ptr
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
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.
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
545 #include <boost/shared_ptr.hpp>
547 $POINTER = boost::shared_ptr
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`.
553 User-defined content {#typemap6}
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.
560 For example, we can add an `#import "wsa5.h"` to the wsdl2h-generated output as
564 #import "import/wsa5.h"
567 which emits the `#import "import/wsa5.h"` literally at the start of the
568 wsdl2h-generated header file.
570 Mapping C/C++ to XML schema {#toxsd}
571 ===========================
573 The soapcpp2 command generates the data binding implementation code from a data
574 binding interface `file.h`:
576 soapcpp2 [options] file.h
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.
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
587 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
588 int prefix__func(arg1, arg2, ..., argn, result);
589 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
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)
596 Overview of serializable C/C++ types {#toxsd1}
597 ------------------------------------
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.
602 ### List of Boolean types
604 | Boolean Type | Notes |
605 | ----------------------------- | ----------------------------------------------------------------------------------- |
606 | `bool` | C++ bool |
607 | `enum xsd__boolean` | C alternative to C++ `bool` with `false_` and `true_` |
609 @see Section [C++ bool and C alternative](#toxsd3).
611 ### List of enumeration and bitmask types
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`) |
620 @see Section [enumerations and bitmasks](#toxsd4).
622 ### List of numerical types
624 | Numerical Type | Notes |
625 | ----------------------------- | ----------------------------------------------------------------------------------- |
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 |
654 @see Section [numerical types](#toxsd5).
656 ### List of string types
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 |
669 @see Section [string types](#toxsd6).
671 ### List of date and time types
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"` |
682 @see Section [date and time types](#toxsd7).
684 ### List of time duration types
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"` |
691 @see Section [time duration types](#toxsd8).
693 ### List of classes and structs
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 |
712 @see Section [classes and structs](#toxsd9).
714 ### List of special classes and structs
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"` |
725 @see Section [special classes and structs](#toxsd10).
727 Colon notation versus name prefixing with XML tag name translation {#toxsd2}
728 ------------------------------------------------------------------
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.
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
743 For example, the following class uses colon notation to bind the `record` class
744 to the `urn:types` schema:
746 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
747 //gsoap ns schema namespace: urn:types
748 class ns:record // binding 'ns:' to a type name
753 ns:record *spouse; // using 'ns:' with the type name
754 ns:record(); // using 'ns:' here too
755 ~ns:record(); // and here
757 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
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.
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.
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).
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:
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
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.
788 - C++11 Unicode identifier name characters in UTF-8 are translated as-is.
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`.
794 Struct/class member and parameter name translation can be overruled by using
795 [backtick XML tags](#toxsd9-5) (with gSOAP 2.8.30 or higher).
797 C++ Bool and C alternatives {#toxsd3}
798 ---------------------------
800 The C++ `bool` type is bound to built-in XSD type `xsd:boolean`.
802 The C alternative is to define an enumeration:
804 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
805 enum xsd__boolean { false_, true_ };
806 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
808 or by defining an enumeration in C with pseudo-scoped enumeration constants:
810 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
811 enum xsd__boolean { xsd__boolean__false, xsd__boolean__true };
812 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
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.
817 To prevent name clashes, `false_` and `true_` have an underscore. Trailing
818 underscores are removed from the XML value space.
820 Enumerations and bitmasks {#toxsd4}
821 -------------------------
823 Enumerations are mapped to XSD simpleType enumeration restrictions of
824 `xsd:string`, `xsd:QName`, and `xsd:long`.
826 Consider for example:
828 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
829 enum ns__Color { RED, WHITE, BLUE };
830 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
832 which maps to a simpleType restriction of `xsd:string` in the soapcpp2-generated
835 <simpleType name="Color">
836 <restriction base="xsd:string">
837 <enumeration value="RED"/>
838 <enumeration value="WHITE"/>
839 <enumeration value="BLUE"/>
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++:
846 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
847 enum ns__Color { ns__Color__RED, ns__Color__WHITE, ns__Color__BLUE };
848 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
850 You can also use C++11 scoped enumerations to prevent name clashes:
852 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
853 enum class ns__Color : int { RED, WHITE, BLUE };
854 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
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
860 The XML value space of the enumertions defined above is `RED`, `WHITE`, and
863 Prefix-qualified enumeration name constants are mapped to simpleType
864 restrictions of `xsd:QName`, for example:
866 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
867 enum ns__types { xsd__int, xsd__float };
868 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
870 which maps to a simpleType restriction of `xsd:QName` in the soapcpp2-generated
873 <simpleType name="types">
874 <restriction base="xsd:QName">
875 <enumeration value="xsd:int"/>
876 <enumeration value="xsd:float"/>
880 Enumeration name constants can be pseudo-numeric as follows:
882 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
883 enum ns__Primes { _3 = 3, _5 = 5, _7 = 7, _11 = 11 };
884 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
886 which maps to a simpleType restriction of `xsd:long`:
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"/>
897 The XML value space of this type is `3`, `5`, `7`, and `11`.
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
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 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
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:
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 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
920 A bitmask type is an `enum*` "product" enumeration with a geometric,
921 power-of-two sequence of values assigned to the enumeration constants:
923 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
924 enum* ns__Options { SSL3, TLS10, TLS11, TLS12 };
925 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
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):
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
938 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
940 The bitmask type maps to a simpleType list restriction of `xsd:string` in the
941 soapcpp2-generated schema:
943 <simpleType name="Options">
945 <restriction base="xsd:string">
946 <enumeration value="SSL3"/>
947 <enumeration value="TLS10"/>
948 <enumeration value="TLS11"/>
949 <enumeration value="TLS12"/>
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`.
959 You can also use C++11 scoped enumerations with bitmasks:
961 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
962 enum* class ns__Options { SSL3, TLS10, TLS11, TLS12 };
963 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
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.
969 To convert `enum` name constants and bitmasks to a string, we use the
970 auto-generated function for enum `T`:
972 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
973 const char *soap_T2s(struct soap*, enum T val)
974 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
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*)`.
980 To convert a string to an `enum` constant or bitmask, we use the auto-generated
983 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
984 int soap_s2T(struct soap*, const char *str, enum T *val)
985 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
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
994 Numerical types {#toxsd5}
997 Integer and floating point types are mapped to the equivalent built-in XSD
998 types with the same sign and bit width.
1000 The `size_t` type is transient (not serializable) because its width is platform
1001 dependent. We recommend to use `uint64_t` instead.
1003 The XML value space of integer types are their decimal representations without
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`
1012 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
1013 soap.float_format = "%g";
1014 soap.double_format = "%lg";
1015 soap.long_double_format = "%Lg";
1016 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
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.
1023 The `long double` extended floating point type requires a custom serializer:
1025 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
1026 #import "custom/long_double.h"
1027 ... use long double ...
1028 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
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`.
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:
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 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1043 To assign these values, use:
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 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1052 If your system supports `__float128` then you can also use this 128 bit
1053 floating point type with a custom serializer:
1055 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
1056 #import "custom/float128.h"
1057 ... use xsd__decimal ...
1058 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1060 Then use the `xsd__decimal` alias of `__float128`, which has a serializer. Do
1061 not use `__float128` directly, which is transient (not serializable).
1063 To check for `INF`, `-INF`, and `NaN` of a `__float128` value use:
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 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
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:
1074 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
1075 typedef int ns__narrow -10 : 10;
1076 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1078 This maps to a simpleType restriction of `xsd:int` in the soapcpp2-generated
1081 <simpleType name="narrow">
1082 <restriction base="xsd:int">
1083 <minInclusive value="-10"/>
1084 <maxInclusive value="10"/>
1088 The lower and upper bound of a range are optional. When omitted, values are
1089 not bound from below or from above, respectively.
1091 The range of a floating point typedef-defined type can be restricted within
1092 floating point constant bounds.
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:
1098 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
1099 typedef float ns__PH "%5.2f" 0.0 : 14.0;
1100 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1102 This maps to a simpleType restriction of `xsd:float` in the soapcpp2-generated
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"/>
1114 For exclusive bounds, we use the `<` operator instead of the `:` range
1117 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
1118 typedef float ns__epsilon 0.0 < 1.0;
1119 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1121 Values `eps` of `ns__epsilon` are restricted between `0.0 < eps < 1.0`.
1123 This maps to a simpleType restriction of `xsd:float` in the soapcpp2-generated
1126 <simpleType name="epsilon">
1127 <restriction base="xsd:float">
1128 <minExclusive value="0"/>
1129 <maxExclusive value="1"/>
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:
1137 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
1138 typedef float ns__pos 0.0 < : ; // 0.0 < pos
1139 typedef float ns__neg : < 0.0 ; // neg < 0.0
1140 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1142 It is valid to make both left and right side exclusive with `< : <` which is in
1143 fact identical to the exlusive range `<` operator:
1145 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
1146 typedef float ns__epsilon 0.0 < : < 1.0; // 0.0 < eps < 1.0
1147 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
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:
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 | |
1164 Besides `float`, also `double` and `long double` values can be restricted. For
1165 example, consider a nonzero probability extended floating point precision type:
1167 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
1168 #import "custom/long_double.h"
1169 typedef long double ns__probability "%16Lg" 0.0 < : 1.0;
1170 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
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
1176 Finally, if your system supports `__int128_t` then you can also use this 128
1177 bit integer type with a custom serializer:
1179 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
1180 #import "custom/int128.h"
1181 ... use xsd__integer ...
1182 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
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).
1187 To convert numeric values to a string, we use the auto-generated function for
1190 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
1191 const char *soap_T2s(struct soap*, T val)
1192 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
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*)`.
1198 To convert a string to a numeric value, we use the auto-generated function
1200 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
1201 int soap_s2T(struct soap*, const char *str, T *val)
1202 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
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.
1210 String types {#toxsd6}
1213 String types are mapped to the built-in `xsd:string` and `xsd:QName` XSD types.
1215 The wide strings `wchar_t*` and `std::wstring` may contain Unicode that is
1216 preserved in the XML value space.
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`.
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.
1226 The length of a string of a typedef-defined string type can be restricted:
1228 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
1229 typedef std::string ns__password 6 : 16;
1230 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1232 which maps to a simpleType restriction of `xsd:string` in the soapcpp2-generated
1235 <simpleType name="password">
1236 <restriction base="xsd:string">
1237 <minLength value="6"/>
1238 <maxLength value="16"/>
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.
1246 In addition, an XSD regex pattern restriction can be associated with a string
1249 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
1250 typedef std::string ns__password "([a-zA-Z]|[0-9]|-)+" 6 : 16;
1251 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1253 which maps to a simpleType restriction of `xsd:string` in the soapcpp2-generated
1256 <simpleType name="password">
1257 <restriction base="xsd:string">
1258 <pattern value="([a-zA-Z0-9]|-)+"/>
1259 <minLength value="6"/>
1260 <maxLength value="16"/>
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)
1268 Exclusive length bounds can be used with strings:
1270 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
1271 typedef std::string ns__string255 : < 256; // same as 0 : 255
1272 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
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:
1278 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
1279 typedef char ns__buffer[10]; // requires soapcpp2 option -b
1280 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1282 which maps to a simpleType restriction of `xsd:string` in the soapcpp2-generated
1285 <simpleType name="buffer">
1286 <restriction base="xsd:string">
1287 <maxLength value="9"/>
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.
1296 Note that raw binary data can be stored in a `xsd__base64Binary` or
1297 `xsd__hexBinary` structure, or transmitted as a MIME attachment.
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:
1304 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
1307 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
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.
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.
1317 To define a `std::string` base type for `xsd:QName`, we use a typedef:
1319 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
1320 typedef std::string xsd__QName;
1321 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1323 The `xsd__QName` string content is normalized, just as with the `_QName`
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.
1330 To define a `std::string` base type for literal XML content, use a typedef:
1332 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
1333 typedef std::string XML;
1334 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
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
1340 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
1341 typedef std::string xsd__token;
1342 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
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.
1349 To copy `char*` or `wchar_t*` strings with a context that manages the allocated
1350 memory, use functions
1352 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
1353 char *soap_strdup(struct soap*, const char*)
1354 wchar_t *soap_wstrdup(struct soap*, const wchar_t*)
1355 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1357 To convert a wide string to a UTF-8 encoded string, use function
1359 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
1360 const char* SOAP_FMAC2 soap_wchar2s(struct soap*, const wchar_t *s)
1361 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1363 The function allocates and returns a string, with its memory being managed by
1366 To convert a UTF-8 encoded string to a wide string, use function
1368 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
1369 int soap_s2wchar(struct soap*, const char *from, wchar_t **to, long minlen, long maxlen)
1370 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
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.
1376 Date and time types {#toxsd7}
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).
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.
1386 A `time_t` value is considered and represented in UTC by the serializer.
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`
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
1398 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
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)
1412 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
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.
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:
1421 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
1422 #import "custom/struct_tm.h" // import typedef struct tm xsd__dateTime;
1423 ... use xsd__dateTime ...
1424 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1426 Compile and link your code with `custom/struct_tm.c`.
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:
1432 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
1433 #import "custom/struct_timeval.h" // import typedef struct timeval xsd__dateTime;
1434 ... use xsd__dateTime ...
1435 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1437 Compile and link your code with `custom/struct_timeval.c`.
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:
1443 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
1446 time_t tv_sec; // seconds since Jan. 1, 1970
1447 suseconds_t tv_usec; // and microseconds
1449 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
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:
1455 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
1456 #import "custom/chrono_time_point.h" // import typedef std::chrono::system_clock::time_point xsd__dateTime;
1457 ... use xsd__dateTime ...
1458 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1460 Compile and link your code with `custom/chrono_time_point.cpp`.
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
1466 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
1467 #import "custom/struct_tm_date.h" // import typedef struct tm xsd__date;
1468 ... use xsd__date ...
1469 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1471 Compile and link your code with `custom/struct_tm_date.c`.
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.
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`).
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
1485 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
1486 #import "custom/long_time.h" // import typedef unsigned long long xsd__time;
1487 ... use xsd__time ...
1488 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1490 Compile and link your code with `custom/long_time.c`.
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.
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.
1501 To convert date and/or time values to a string, we use the auto-generated
1502 function for type `T`:
1504 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
1505 const char *soap_T2s(struct soap*, T val)
1506 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
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*)`.
1512 To convert a string to a date/time value, we use the auto-generated function
1514 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
1515 int soap_s2T(struct soap*, const char *str, T *val)
1516 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
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
1523 Time duration types {#toxsd8}
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.
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:
1535 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
1536 #import "custom/duration.h" // import typedef long long xsd__duration;
1537 ... use xsd__duration ...
1538 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1540 Compile and link your code with `custom/duration.c`.
1542 The duration type `xsd__duration` can represent 106,751,991,167 days forward
1543 and backward with millisecond precision.
1545 Durations that exceed a month are always output in days, rather than months to
1546 avoid days-per-month conversion inacurracies.
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
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`.
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`:
1564 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
1565 #import "custom/chrono_duration.h" // import typedef std::chrono::duration xsd__duration;
1566 ... use xsd__duration ...
1567 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1569 Compile and link your code with `custom/chrono_duration.cpp`.
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).
1574 The same observations with respect to receiving durations in years and months
1575 apply to this serializer's decoder.
1577 To convert duration values to a string, we use the auto-generated function
1579 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
1580 const char *soap_xsd__duration2s(struct soap*, xsd__duration val)
1581 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
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.
1587 To convert a string to a duration value, we use the auto-generated function
1589 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
1590 int soap_s2xsd__dateTime(struct soap*, const char *str, xsd__dateTime *val)
1591 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1593 The function returns `SOAP_OK` on success or an error when the value is not a
1596 Classes and structs {#toxsd9}
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.
1604 Classes that are declared with the gSOAP tools are limited to single
1605 inheritence only. Structs cannot be inherited.
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):
1610 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
1611 //gsoap ns schema namespace: urn:types
1623 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
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.
1629 The class maps to a complexType in the soapcpp2-generated schema:
1631 <complexType name="record">
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"/>
1639 ### Serializable versus transient types and members {#toxsd9-1}
1641 Public data members of a class or struct are serialized. Private and protected
1642 members are transient and not serializable.
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:
1648 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
1649 extern class std::ostream; // declare 'std::ostream' transient
1653 extern int num; // not serialized
1654 std::ostream out; // not serialized
1655 static const int MAX = 1024; // not serialized
1657 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
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
1663 ### Volatile classes and structs {#toxsd9-2}
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.
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:
1672 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
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
1682 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
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.
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
1692 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
1693 volatile struct ns:tm { ... }
1694 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1696 This struct maps to a complexType in the soapcpp2-generated schema:
1698 <complexType name="tm">
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"/>
1709 ### Mutable classes and structs {#toxsd9-3}
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.
1722 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
1723 mutable struct ns__tuple
1728 mutable struct ns__tuple
1733 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
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:
1740 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
1741 mutable struct ns__tuple
1743 float value; // BAD: value is already declared std::string
1745 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
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.
1751 ### Default member values in C and C++ {#toxsd9-4}
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
1757 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
1761 std::string name = "Joe";
1764 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1766 Alternatively, use C++11 default initialization syntax:
1768 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
1772 std::string name { "Joe" };
1775 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
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.
1781 You can explicitly (re)initialize an object with these initial values by using
1782 the soapcpp2 auto-generated functions:
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++).
1787 Initializations can only be provided for members that have primitive types
1788 (`bool`, `enum`, `time_t`, numeric and string types).
1790 @see Section [operations on classes and structs](#toxsd9-13).
1792 ### Attribute members and backtick XML tags {#toxsd9-5}
1794 Class and struct data members are declared as XML attributes by annotating
1795 their type with a `@` qualifier:
1797 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
1805 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1807 This class maps to a complexType in the soapcpp2-generated schema:
1809 <complexType name="record">
1811 <element name="spouse" type="ns:record" minOccurs="0" maxOccurs="1" nillable="true"/>
1813 <attribute name="name" type="xsd:string" use="required"/>
1814 <attribute name="SSN" type="xsd:unsignedLong" use="required"/>
1817 An example XML instance of `ns__record` is:
1819 <ns:record xmlns:ns="urn:types" name="Joe" SSN="1234567890">
1820 <spouse name="Jane" SSN="1987654320">
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.
1830 Attribute data members can be pointers and smart pointers to these types, which
1831 permits attributes to be optional.
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).
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
1840 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
1844 @std::string name `full-name`;
1845 @uint64_t SSN `tax-id`;
1846 ns__record *spouse `married-to`;
1848 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1850 This class maps to a complexType in the soapcpp2-generated schema:
1852 <complexType name="record">
1854 <element name="married-to" type="ns:record" minOccurs="0" maxOccurs="1" nillable="true"/>
1856 <attribute name="full-name" type="xsd:string" use="required"/>
1857 <attribute name="tax-id" type="xsd:unsignedLong" use="required"/>
1860 An example XML instance of `ns__record` is:
1862 <ns:record xmlns:ns="urn:types" full-name="Joe" tax-id="1234567890">
1863 <married-to full-name="Jane" tax-id="1987654320">
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:
1871 @uint64_t SSN `tax-id` 0:1 = 999;
1873 ### Qualified and unqualified members {#toxsd9-6}
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.
1884 The XML schema elementFormDefault and attributeFormDefault declarations control
1885 the tag name qualification of local elements and attributes, respectively.
1887 - "unqualified" indicates that local elements/attributes are not qualified with
1888 the namespace prefix.
1890 - "qualified" indicates that local elements/attributes must be qualified with
1891 the namespace prefix.
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
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:
1901 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
1902 //gsoap ns schema namespace: urn:types
1903 //gsoap ns schema elementForm: qualified
1904 //gsoap ns schema attributeForm: unqualified
1912 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1914 This class maps to a complexType in the soapcpp2-generated schema with
1915 targetNamespace "urn:types", elementFormDefault qualified and
1916 attributeFormDefault unqualified:
1918 <schema targetNamespace="urn:types"
1920 elementFormDefault="qualified"
1921 attributeFormDefault="unqualified"
1923 <complexType name="record">
1925 <element name="spouse" type="ns:record" minOccurs="0" maxOccurs="1" nillable="true"/>
1927 <attribute name="name" type="xsd:string" use="required"/>
1928 <attribute name="SSN" type="xsd:unsignedLong" use="required"/>
1932 An example XML instance of `ns__record` is:
1934 <ns:record xmlns:ns="urn:types" name="Joe" SSN="1234567890">
1935 <ns:spouse> name="Jane" SSN="1987654320">
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.
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:
1947 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
1948 //gsoap ns schema namespace: urn:types
1949 //gsoap ns schema elementForm: qualified
1950 //gsoap ns schema attributeForm: unqualified
1954 @std::string ns:name; // 'ns:' qualified
1956 ns__record *:spouse; // ':' unqualified (empty prefix)
1958 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
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:
1964 <schema targetNamespace="urn:types"
1966 elementFormDefault="unqualified"
1967 attributeFormDefault="unqualified"
1969 <complexType name="record">
1971 <element name="spouse" type="ns:record" minOccurs="0" maxOccurs="1" nillable="true" form="unqualified"/>
1973 <attribute name="name" type="xsd:string" use="required" form="qualified"/>
1974 <attribute name="SSN" type="xsd:unsignedLong" use="required"/>
1978 XML instances of `ns__record` have unqualified spouse elements and qualified
1981 <ns:record xmlns:ns="urn:types" ns:name="Joe" SSN="1234567890">
1982 <spouse> ns:name="Jane" SSN="1987654320">
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).
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 or higher).
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
1999 ### Defining document root elements {#toxsd9-7}
2001 To define and reference XML document root elements we use type names that start
2004 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
2006 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2008 Alternatively, we can use a typedef to define a document root element with a
2011 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
2012 typedef ns__record _ns__record;
2013 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2015 This typedef maps to a global root element that is added to the
2016 soapcpp2-generated schema:
2018 <element name="record" type="ns:record"/>
2020 An example XML instance of `_ns__record` is:
2022 <ns:record xmlns:ns="urn:types">
2024 <SSN>1234567890</SSN>
2027 <SSN>1987654320</SSN>
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
2035 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
2036 typedef std::string _ns__name 1 : 100;
2040 @_QName xsi__type; // built-in XSD attribute xsi:type
2041 _ns__name ns__name; // ref to global ns:name element
2043 _ns__record *spouse;
2045 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2047 These types map to the following comonents in the soapcpp2-generated schema:
2049 <simpleType name="name">
2050 <restriction base="xsd:string">
2051 <minLength value="1"/>
2052 <maxLength value="100"/>
2055 <element name="name" type="ns:name"/>
2056 <complexType name="record">
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"/>
2062 <attribute ref="xsi:type" use="optional"/>
2064 <element name="record" type="ns:record"/>
2066 Use only use qualified member names when their types match the global-level
2067 element types that they refer to. For example:
2069 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
2070 typedef std::string _ns__name; // global element ns:name of type xsd:string
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
2078 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
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
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).
2088 As an alternative to prefixing member names, use the backtick tag (gSOAP 2.8.30
2091 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
2092 typedef std::string _ns__name 1 : 100;
2096 @_QName t `xsi:type`; // built-in XSD attribute xsi:type
2097 _ns__name s `ns:name`; // ref to global ns:name element
2099 _ns__record *spouse;
2101 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2103 ### (Smart) pointer members and their occurrence constraints {#toxsd9-8}
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).
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
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:
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.
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.
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.
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.
2136 Consider for example:
2138 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
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)
2146 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2148 This class maps to a complexType in the soapcpp2-generated schema:
2150 <complexType name="record">
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"/>
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:
2161 <ns:record xmlns:ns="urn:types" ...>
2164 <spouse xsi:nil="true"/>
2167 @note In general, a smart pointer is simply declared as a `volatile` template
2168 in a gSOAP header file for soapcpp2:
2170 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
2171 volatile template <class T> class NAMESPACE::shared_ptr;
2172 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
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
2179 ### Container members and their occurrence constraints {#toxsd9-9}
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.
2186 You can use `std::deque`, `std::list`, `std::vector`, and `std::set` containers
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 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2197 For example, to use a vector data mamber to store names in a record:
2199 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
2200 #import "import/stlvector.h"
2204 std::vector<std::string> names;
2207 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
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`:
2213 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
2214 #import "import/stlvector.h"
2218 std::vector<std::string> names 1:10;
2221 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2223 This class maps to a complexType in the soapcpp2-generated schema:
2225 <complexType name="record">
2227 <element name="name" type="xsd:string" minOccurs="1" maxOccurs="10"/>
2228 <element name="SSN" type="xsd:unsignedLong" minOccurs="1" maxOccurs="1""/>
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:
2237 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
2238 template <class T> class std::vector;
2239 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
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`
2245 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
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 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2255 @note For more details see the example `simple_vector` container with
2256 documentation in the package under `gsoap/samples/template`.
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
2265 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
2268 $int sizeofnames; // array size
2269 char* *names; // array of char* names
2272 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2274 This class maps to a complexType in the soapcpp2-generated schema:
2276 <complexType name="record">
2278 <element name="name" type="xsd:string" minOccurs="0" maxOccurs="unbounded" nillable="true"/>
2279 <element name="SSN" type="xsd:unsignedLong" minOccurs="1" maxOccurs="1""/>
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`:
2287 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
2290 $int sizeofnames 1:10; // array size 1..10
2291 char* *names; // array of one to ten char* names
2294 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2296 This class maps to a complexType in the soapcpp2-generated schema:
2298 <complexType name="record">
2300 <element name="name" type="xsd:string" minOccurs="1" maxOccurs="10" nillable="true"/>
2301 <element name="SSN" type="xsd:unsignedLong" minOccurs="1" maxOccurs="1""/>
2305 ### Tagged union members {#toxsd9-10}
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*.
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
2316 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
2320 $int xORnORs; // variant selector with values SOAP_UNION_fieldname
2329 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
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`:
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).
2340 This class maps to a complexType with a sequence and choice in the
2341 soapcpp2-generated schema:
2343 <complexType name="record">
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"/>
2350 <element name="names" type="xsd:string" minOccurs="1" maxOccurs="1" nillable="true"/>
2354 An STL container or dynamic array of a union requires wrapping the variant
2355 selector and union member in a struct:
2357 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
2362 struct ns__data // data with a choice of x, n, or s
2364 $int xORnORs; // variant selector with values SOAP_UNION_fieldname
2371 }> data; // vector with data
2373 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2375 and an equivalent definition with a dynamic array instead of a `std::vector`
2376 (you can use this in C with structs):
2378 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
2382 $int sizeOfdata; // size of dynamic array
2383 struct ns__data // data with a choice of x, n, or s
2385 $int xORnORs; // variant selector with values SOAP_UNION_fieldname
2392 } *data; // points to the data array of length sizeOfdata
2394 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2396 This maps to two complexTypes in the soapcpp2-generated schema:
2398 <complexType name="data">
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"/>
2405 <complexType name="record">
2407 <element name="data" type="ns:data" minOccurs="0" maxOccurs="unbounded"/>
2411 The XML value space consists of a sequence of item elements each wrapped in an
2414 <ns:record xmlns:ns="urn:types" ...>
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):
2434 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
2438 $int sizeOfdata; // size of dynamic array
2439 struct __data // contains choice of x, n, or s
2441 $int xORnORs; // variant selector with values SOAP_UNION_fieldname
2448 } *__data; // points to the data array of length sizeOfdata
2450 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2452 This maps to a complexType in the soapcpp2-generated schema:
2454 <complexType name="record">
2455 <sequence minOccurs="0" maxOccurs="unbounded">
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"/>
2464 The XML value space consists of a sequence of `<x>`, `<n>`, and/or `<s>`
2467 <ns:record xmlns:ns="urn:types" ...>
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.
2480 ### Tagged void pointer members {#toxsd9-11}
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:
2488 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
2492 $int typeOfdata; // type tag with values SOAP_TYPE_T
2493 void *data; // points to some data of type T
2495 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
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*`).
2501 This class maps to a complexType with a sequence in the soapcpp2-generated
2504 <complexType name="record">
2506 <element name="data" type="xsd:anyType" minOccurs="0" maxOccurs="1"/>
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:
2513 <ns:record xmlns:ns="urn:types" ...>
2514 <data xsi:type="xsd:int">123</data>
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.
2521 You can find the `SOAP_TYPE_T` name of each serializable type in the
2522 auto-generated soapStub.h file.
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.
2527 When the `void*` pointer is NULL or when `typeOfdata` is zero, the data is not
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:
2533 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
2538 struct ns__data // data with an xsd:anyType item
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
2544 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2546 and an equivalent definition with a dynamic array instead of a `std::vector`
2547 (you can use this in C with structs):
2549 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
2553 $int sizeOfdata; // size of dynamic array
2554 struct ns__data // data with an xsd:anyType item
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
2560 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2562 This maps to two complexTypes in the soapcpp2-generated schema:
2564 <complexType name="data">
2566 <element name="item" type="xsd:anyType" minOccurs="1" maxOccurs="1" nillable="true"/>
2569 <complexType name="record">
2571 <element name="data" type="ns:data" minOccurs="0" maxOccurs="unbounded"/>
2575 The XML value space consists of a sequence of item elements each wrapped in a
2578 <ns:record xmlns:ns="urn:types" ...>
2580 <item xsi:type="xsd:int">123</item>
2583 <item xsi:type="xsd:double">3.1</item>
2586 <item xsi:type="xsd:string">abc</item>
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):
2595 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
2599 $int sizeOfdata; // size of dynamic array
2600 struct __data // contains xsd:anyType item
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
2606 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2608 This maps to a complexType in the soapcpp2-generated schema:
2610 <complexType name="record">
2611 <sequence minOccurs="0" maxOccurs="unbounded">
2612 <element name="item" type="xsd:anyType" minOccurs="1" maxOccurs="1"/>
2616 The XML value space consists of a sequence of data elements:
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>
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.
2630 @see Section [XSD type bindings](#typemap2).
2632 ### Adding get and set methods {#toxsd9-12}
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.
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.
2645 For example, adding a `set` and `get` method to a class declaration:
2647 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
2651 int set(struct soap*); // triggered before serialization
2652 int get(struct soap*); // triggered after deserialization
2655 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2657 To add these and othe rmethods to classes and structs with wsdl2h and
2658 `typemap.dat`, please see [class/struct member additions](#typemap3).
2660 ### Operations on classes and structs {#toxsd9-13}
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
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`.
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`.
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).
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
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.
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
2702 The public methods added to a class `T`:
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.
2707 - `virtual void T::soap_default(struct soap*)` sets all data members to
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.
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)`.
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)`.
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)`.
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)`
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.
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.
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.
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:
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.
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.
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).
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 `...`.
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.
2776 Special classes and structs {#toxsd10}
2777 ---------------------------
2779 ### SOAP encoded arrays {#toxsd10-1}
2781 A class or struct with the following layout is a one-dimensional SOAP encoded
2784 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
2788 T *__ptr; // array pointer
2789 int __size; // array size
2791 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2793 where `T` is the array element type. A multidimensional SOAP Array is:
2795 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
2799 T *__ptr; // array pointer
2800 int __size[N]; // array size of each dimension
2802 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
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.
2807 This maps to a complexType restriction of SOAP-ENC:Array in the
2808 soapcpp2-generated schema:
2810 <complexType name="ArrayOfT">
2812 <restriction base="SOAP-ENC:Array">
2814 <element name="item" type="T" minOccurs="0" maxOccurs="unbounded" nillable="true"/>
2816 <attribute ref="SOAP-ENC:arrayType" WSDL:arrayType="ArrayOfT[]"/>
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.
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:
2827 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
2831 T *__ptr; // array pointer
2832 int __size[N]; // array size of each dimension
2833 int __offset[N]; // array offsets to start each dimension
2835 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2837 For example, we can define a matrix of floats as follows:
2839 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
2846 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2848 The following code populates the matrix and serializes it in XML:
2850 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
2851 soap *soap = soap_new1(SOAP_XML_INDENT);
2853 double a[6] = { 1, 2, 3, 4, 5, 6 };
2857 soap_write_Matrix(soap, &A);
2858 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2860 Matrix A is serialized as an array with 2x3 values:
2862 <SOAP-ENC:Array SOAP-ENC:arrayType="xsd:double[2,3]" ...>
2871 ### XSD hexBinary and base64Binary types {#toxsd10-2}
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`:
2876 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
2877 class xsd__hexBinary
2880 unsigned char *__ptr; // points to raw binary data
2881 int __size; // size of data
2883 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2887 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
2888 class xsd__base64Binary
2891 unsigned char *__ptr; // points to raw binary data
2892 int __size; // size of data
2894 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2896 ### MIME/MTOM attachment binary types {#toxsd10-3}
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:
2901 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
2902 //gsoap xop schema import: http://www.w3.org/2004/08/xop/include
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
2912 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
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.
2918 ### Wrapper class/struct with simpleContent {#toxsd10-4}
2920 A class or struct with the following layout is a complexType that wraps
2923 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
2929 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
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
2935 This maps to a complexType with simpleContent in the soapcpp2-generated schema:
2937 <complexType name="simple">
2939 <extension base="T"/>
2943 A wrapper class/struct may include any number of attributes declared with `@`.
2945 ### DOM anyType and anyAttribute {#toxsd10-5}
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:
2950 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
2956 @xsd__anyAttribute attributes; // list of DOM attributes
2958 xsd__anyType *name; // optional DOM element
2960 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
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
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.
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:
2976 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
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
2987 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2989 where the members prefixed with `__` are "invisible" to the XML parser, meaning
2990 that these members are not bound to XML tag names.
2992 In C you can use a dynamic arrary instead of `std::vector`:
2994 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.c}
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
3005 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3007 Classes can inherit DOM, which enables full use of polymorphism with one base
3010 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
3013 class ns__record : public xsd__anyType
3016 std::vector<xsd__anyType*> array; // array of objects of any class
3019 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
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.
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.
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`:
3035 xsd__any = | xsd__anyType*
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`:
3041 xsd__anyType = | xsd__anyType*
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:
3047 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
3048 class xsd__anyType { _XML __item; struct soap *soap; };
3050 class ns__record : public xsd__anyType
3054 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3056 where the `_XML __item` member holds any XML content as a literal XML string.
3058 To use the DOM API, compile `dom.c` (or `dom.cpp` for C++), or link with
3059 `-lgsoapssl` (or `-lgsoapssl++` for C++).
3061 @see Documentation of [XML DOM and XPath](http://www.genivia.com/doc/dom/html)
3064 Directives {#directives}
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.
3073 Service directives are applicable to service and operations described by WSDL.
3074 Schema directives are applicable to types, elements, and attributes defined by
3077 Service directives {#directives-1}
3080 A service directive must start at a new line and is of the form:
3082 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
3083 //gsoap <prefix> service <property>: <value>
3084 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3086 where `<prefix>` is the XML namespace prefix of a service binding. The
3087 `<property>` and `<value>` fields are one of the following:
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 |
3109 The service `name` and `namespace` properties are required in order to generate
3110 a valid WSDL with soapcpp2. The other properties are optional.
3112 The `style` and `encoding` property defaults are changed with soapcpp2 option
3113 `-e` to `rpc` and `encoded`, respectively.
3115 The `protocol` property is `SOAP` by default (SOAP 1.1). Protocol property
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 |
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:
3136 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
3137 int prefix__func(arg1, arg2, ..., argn, result);
3138 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
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
3144 Service method directives {#directives-2}
3145 -------------------------
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.
3150 A service method directive is of the form:
3152 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
3153 //gsoap <prefix> service method-<property>: <method> <value>
3154 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
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:
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) |
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.
3185 The `method-fault` property can be repeated for a service operation to declare
3186 multiple faults that the service operation may return.
3188 The `method-action` property serves two purposes:
3190 -# To set the SOAPAction header for SOAP protocols, i.e. sets the
3191 definitions/binding/operation/SOAP:operation/\@soapAction.
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 `/`).
3198 Use `method-input-action` and `method-output-action` to differentiate the
3199 SOAPAction between SOAP request and response messages.
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.
3206 The `method-mime-type` property serves two purposes:
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.
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).
3221 Use `method-input-mime-type` and `method-output-mime-type` to differentiate the
3222 attachment types between SOAP request and response messages.
3224 Schema directives {#directives-3}
3227 A schema directive is of the form:
3229 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
3230 //gsoap <prefix> schema <property>: <value>
3231 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3233 where `<prefix>` is the XML namespace prefix of a schema. The `<property>` and
3234 `<value>` fields are one of the following:
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 |
3246 To learn more about the local form defaults, see [qualified and unqualified members.](#toxsd9-6)
3248 The `typed` property is implicitly `yes` when soapcpp2 option `-t` is used.
3250 Schema type directives {#directives-4}
3251 ----------------------
3253 A schema type directive is of the form:
3255 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
3256 //gsoap <prefix> schema type-<property>: <name> <value>
3257 //gsoap <prefix> schema type-<property>: <name>::<member> <value>
3258 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
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.
3264 You can describe a type:
3266 | Type Property | Value |
3267 | -------------------- | ------------------------------- |
3268 | `type-documentation` | text describing the schema type |
3269 | `type` | same as above, shorthand form |
3271 For example, you can add a description to an enumeration:
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 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3279 This documented enumeration maps to a simpleType restriction of `xsd:string` in
3280 the soapcpp2-generated schema:
3282 <simpleType name="Vowels">
3284 <documentation>The letters A, E, I, O, U, and sometimes Y</documentation>
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">
3294 <documentation>A vowel, sometimes</documentation>
3300 Serialization rules {#rules}
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.
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.
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).
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.
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.
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
3330 SOAP document versus rpc style {#doc-rpc}
3331 ------------------------------
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.
3339 For example, the following directives in the gSOAP header file for soapcpp2
3340 declare that `DBupdate` is a SOAP RPC encoding service method:
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 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
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:
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"
3363 </SOAP-ENV:Envelope>
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).
3372 SOAP literal versus encoding {#lit-enc}
3373 ----------------------------
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
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
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.
3390 For example, the following directives in the gSOAP header file for soapcpp2
3391 declare that `DBupdate` is a SOAP RPC encoding service method:
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 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
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:
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"
3411 <SOAP-ENV:Body SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
3413 <records SOAP-ENC:arrayType="ns:record[3]">
3416 <SSN>1234567890</SSN>
3420 <SSN>1987654320</SSN>
3424 <SSN>2345678901</SSN>
3428 <id id="_1" xsi:type="xsd:string">Joe</id>
3430 </SOAP-ENV:Envelope>
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.
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
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"
3446 <SOAP-ENV:Body SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
3448 <records SOAP-ENC:arrayType="ns:record[3]">
3454 <id id="id1" xsi:type="ns:record">
3456 <SSN>1234567890</SSN>
3458 <id id="id2" xsi:type="ns:record">
3460 <SSN>1987654320</SSN>
3462 <id id="id3" xsi:type="ns:record">
3464 <SSN>2345678901</SSN>
3466 <id id="id4" xsi:type="xsd:string">Joe</id>
3467 <id id="id5" xsi:type="xsd:string">Jane</id>
3469 </SOAP-ENV:Envelope>
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:
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"
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">
3484 <name SOAP-ENC:id="_1">Joe</name>
3485 <SSN>1234567890</SSN>
3489 <SSN>1987654320</SSN>
3492 <name SOAP-ENC:ref="_1"/>
3493 <SSN>2345678901</SSN>
3498 </SOAP-ENV:Envelope>
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
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.
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.
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.
3518 SOAP 1.1 versus SOAP 1.2 {#soap}
3519 ------------------------
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:
3525 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
3526 //gsoap ns service method-protocol: DBupdate SOAP1.2
3527 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
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.
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
3539 The SOAP 1.2 protocol default can also be set by importing and loading
3540 `gsoap/import/soap12.h`:
3542 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
3544 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3546 Non-SOAP XML serialization {#non-soap}
3547 --------------------------
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).
3555 You can read and write XML directly to a file or stream with the serializing
3556 [operations on classes and structs](#toxsd9-13).
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.
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:
3567 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
3568 //gsoap ns service namespace: urn:DB
3569 //gsoap ns service method-protocol: DBupdate POST
3570 int ns__DBupdate(...);
3571 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
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:
3578 <ns:DBupdate xmln:ns="urn:DB" ...>
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:
3587 <ns:DBupdate xmln:ns="urn:DB" ...>
3590 <name id="_1">Joe</name>
3591 <SSN>1234567890</SSN>
3595 <SSN>1987654320</SSN>
3599 <SSN>2345678901</SSN>
3604 Input and output {#io}
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:
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 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
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.
3625 Note: the use of `soap->is` and `soap->os` in C requires gSOAP 2.8.28 or later.
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.
3630 In addition, you can set IO callback functions to handle IO at a lower level.
3632 For more details, see the [gSOAP user guide.](http://www.genivia.com/doc/soapdoc2.html)
3634 Reading and writing from/to files and streams {#io1}
3635 ---------------------------------------------
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
3641 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
3642 FILE *fp = fopen("record.xml", "r");
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
3649 soap->recvfd = 0; // read from stdin, or -1 to block reading
3652 FILE *fp = fopen("record.xml", "w");
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
3659 soap->sendfd = 1; // write to stdout, or -1 to block writing
3661 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3663 Similar code with streams in C++:
3665 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
3669 fs.open("record.xml", std::ios::in);
3673 if (soap_read__ns__record(soap, &pers1))
3674 ... // handle IO error
3679 fs.open("record.xml", std::ios::out);
3683 if (soap_write__ns__record(soap, &pers1))
3684 ... // handle IO error
3688 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3690 Reading and writing from/to string buffers {#io2}
3691 ------------------------------------------
3693 For C++ we recommend to use `std::stringstream` objects from `<sstream>` as
3694 illustrated in the following example:
3696 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
3699 std::stringstream ss;
3700 ss.str("..."); // XML to parse
3702 if (soap_read__ns__record(soap, &pers1))
3703 ... // handle IO error
3707 if (soap_write__ns__record(soap, &pers1))
3708 ... // handle IO error
3710 std::string s = ss.str(); // string with XML
3711 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
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):
3716 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
3717 soap->is = "..."; // XML to parse
3718 if (soap_read__ns__record(soap, &pers1))
3719 ... // handle IO error
3722 const char *cs = NULL;
3724 if (soap_write__ns__record(soap, &pers1))
3725 ... // handle IO error
3727 ... = cs; // string with XML (do not free(cs): managed by the context and freed with soap_end())
3728 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
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.
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)
3737 Memory management {#memory}
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.
3744 Memory management in C {#memory1}
3745 ----------------------
3747 In C (wsdl2h option `-c` and soapcpp2 option `-c`), the gSOAP engine allocates
3748 data on a context-managed heap with:
3750 - `void *soap_malloc(struct soap*, size_t len)`.
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:
3756 - `void *soap_memdup(struct soap*, const void *src, size_t len)`
3758 This function returns a pointer to the copy. This function requires gSOAP
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)`:
3765 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
3769 struct soap *soap = soap_new(); // new context
3771 struct ns__record *record = soap_malloc(soap, sizeof(struct ns__record));
3772 soap_default_ns__record(soap, record); // auto-generated struct initializer
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 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
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.
3783 To make `char*` and `wchar_t*` string copies to the context-managed heap, we
3784 can use the functions:
3786 - `char *soap_strdup(struct soap*, const char *str)` and
3787 - `wchar_t *soap_wstrdup(struct soap*, const wchar_t *wstr)`.
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:
3792 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
3793 #define soap_assign(soap, lhs, rhs) (*(lhs = (typeof(lhs))soap_malloc(soap, sizeof(*lhs))) = rhs)
3794 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3796 Pointers to primitive values are often used for optional members. For example,
3797 assume we have the following struct:
3799 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
3802 const char *name; // required name
3803 uint64_t *SSN; // optional SSN
3804 struct ns__record *spouse; // optional spouse
3806 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3808 Use `soap_assign` to create a SSN value on the managed heap:
3810 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
3811 struct soap *soap = soap_new(); // new context
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);
3818 soap_end(soap); // delete managed soap_malloc'ed heap data
3819 soap_free(soap); // delete context
3820 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
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
3826 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
3827 assert((record->SSN = (uint64_t*)soap_malloc(soap, sizeof(utint64_t))) != NULL);
3828 *record->SSN = 1234567890LL;
3829 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3831 The gSOAP serializer can serialize any heap, stack, or static allocated data.
3832 So we can also create a new record as follows:
3834 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
3835 struct soap *soap = soap_new(); // new context
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
3843 soap_end(soap); // delete managed soap_malloc'ed heap data
3844 soap_free(soap); // delete context
3845 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
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
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);
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 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
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:
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 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
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.
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:
3882 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
3883 struct ns__record *other_record = soap_dup_ns__record(NULL, NULL, record);
3885 soap_del_ns__record(other_record); // deep delete record data members
3886 free(other_record); // delete the record
3887 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3889 Cycles in the data structure will lead to non-termination when making unmanaged
3890 deep copies. Consider for example:
3892 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
3895 const char *name; // required name
3896 uint64_t SSN; // required SSN
3897 struct ns__record *spouse; // optional spouse
3899 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3901 The code to populate a structure with a mutual spouse relationship:
3903 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
3904 struct soap *soap = soap_new();
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;
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 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
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:
3926 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
3927 FILE *fp = fopen("record.xml", "w");
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);
3935 soap->sendfd = -1; // block further writing
3937 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3939 which produces an XML document record.xml that is similar to:
3941 <ns:record xmlns:ns="urn:types" id="Joe">
3943 <SSN>1234567890</SSN>
3946 <SSN>1987654320</SSN>
3947 <spouse ref="#Joe"/>
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:
3955 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
3956 struct soap *soap = soap_new1(SOAP_XML_GRAPH); // support id-ref w/o SOAP
3958 struct ns__record pers1;
3959 FILE *fp = fopen("record.xml", "r");
3962 soap->recvfd = fileno(fp);
3963 if (soap_read_ns__record(soap, &pers1))
3964 ... // handle IO error
3966 soap->recvfd = -1; // blocks further reading
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 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
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()`.
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.
3983 Memory management in C++ {#memory2}
3984 ------------------------
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)`.
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)`.
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:
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.
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.
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).
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 `...`.
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.
4019 For example, to allocate a managed `std::string` you can use:
4021 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
4022 std::string *s = soap_new_std__string(soap);
4023 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
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.
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`):
4034 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
4036 T * soap_make(struct soap *soap, T val)
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
4043 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4045 For example, assuming we have the following class:
4047 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
4051 std::string name; // required name
4052 uint64_t *SSN; // optional SSN
4053 ns__record *spouse; // optional spouse
4055 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
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
4061 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
4062 soap *soap = soap_new(); // new context
4064 ns__record *record = soap_new_set_ns__record(
4067 soap_make<uint64_t>(soap, 1234567890LL),
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 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
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:
4078 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
4079 uint64_t SSN = 1234567890LL;
4080 ns__record *record = soap_new_set_ns__record(soap, "Joe", &SSN, NULL);
4081 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
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`.
4088 To facilitate class methods to access the managing context, we can add a soap
4089 context pointer to a class/struct:
4091 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
4095 void create_more(); // needs a context to create more internal data
4097 struct soap *soap; // the context that manages this instance, or NULL
4099 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4101 The context is set when invoking `soap_new_T` (and similar) with a non-NULL
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:
4108 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
4109 soap *other_soap = soap_new(); // another context
4110 ns__record *other_record = soap_dup_ns__record(other_soap, NULL, record);
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 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
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*)`:
4120 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
4121 soap *other_soap = soap_new(); // another context
4122 ns__record *other_record = record->soap_dup(other_soap);
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 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
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:
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 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
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.
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:
4150 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
4151 ns__record *other_record = record->soap_dup(NULL);
4153 other_record->soap_del(); // deep delete record data members
4154 delete other_record; // delete the record
4155 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4157 Cycles in the data structure will lead to non-termination when making unmanaged
4158 deep copies. Consider for example:
4160 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
4163 const char *name; // required name
4164 uint64_t SSN; // required SSN
4165 ns__record *spouse; // optional spouse
4167 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4169 The code to populate a structure with a mutual spouse relationship:
4171 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
4172 soap *soap = soap_new();
4174 ns__record pers1, pers2;
4176 pers1.SSN = 1234567890;
4177 pers1.spouse = &pers2;
4178 pers2.name = "Jane";
4179 pers2.SSN = 1987654320;
4180 pers2.spouse = &pers1;
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 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
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:
4192 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
4193 FILE *fp = fopen("record.xml", "w");
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
4202 soap->sendfd = -1; // block further writing
4204 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4206 which produces an XML document record.xml that is similar to:
4208 <ns:record xmlns:ns="urn:types" id="Joe">
4210 <SSN>1234567890</SSN>
4213 <SSN>1987654320</SSN>
4214 <spouse ref="#Joe"/>
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:
4222 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
4223 soap *soap = soap_new1(SOAP_XML_GRAPH); // support id-ref w/o SOAP
4226 FILE *fp = fopen("record.xml", "r");
4229 soap->recvfd = fileno(fp); // file descriptor to read from
4230 if (soap_read_ns__record(soap, &pers1))
4231 ... // handle IO error
4233 soap->recvfd = -1; // block further reading
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 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
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()`.
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.
4251 Context flags to initialize the soap struct {#flags}
4252 ===========================================
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()` for
4256 heap allocation of contexts:
4258 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
4259 struct soap *soap = soap_new1(<flag> | <flag> ... | <flag>);
4261 soap_destroy(soap); // delete objects
4262 soap_end(soap); // delete other data and temp data
4263 soap_free(soap); // free context
4264 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4266 and with `soap_init1()` with stack allocated contexts:
4268 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
4270 soap_init1(&soap, <flag> | <flag> ... | <flag>);
4272 soap_destroy(&soap); // delete objects
4273 soap_end(&soap); // delete other data and temp data
4274 soap_done(&soap); // clear context
4275 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4277 where `<flag>` is one of:
4279 - `SOAP_C_UTFSTRING`: enables all `std::string` and `char*` strings to
4280 contain UTF-8 content. This option is recommended.
4282 - `SOAP_C_NILSTRING`: treat empty strings as if they were NULL pointers, i.e.
4283 omits elements and attributes when empty.
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.
4290 - `SOAP_XML_INDENT`: produces indented XML.
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.
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.
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.
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!).
4308 - `SOAP_XML_NIL`: emit empty element with `xsi:nil` for all NULL pointers
4311 - `SOAP_XML_IGNORENS`: the XML parser ignores XML namespaces, i.e. element and
4312 attribute tag names match independent of their namespace.
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.
4320 - `SOAP_IO_CHUNK`: to enable HTTP chunked transfers.
4322 - `SOAP_IO_STORE`: full buffering of outbound messages.
4324 - `SOAP_ENC_ZLIB`: compress messages, requires compiling with `-DWITH_GZIP` and
4325 linking with zlib (`-lz`).
4327 - `SOAP_ENC_MIME`: enable MIME attachments, see
4328 [MIME/MTOM attachment binary types](#toxsd10-3).
4330 - `SOAP_ENC_MTOM`: enable MTOM attachments, see
4331 [MIME/MTOM attachment binary types](#toxsd10-3).
4333 Features and limitations {#features}
4334 ========================
4336 In general, to use the generated code:
4338 - Make sure to `#include "soapH.h"` in your code and also define a namespace
4339 table or `#include "ns.nsmap"` with the generated table, where `ns` is the
4340 namespace prefix for services.
4342 - Use soapcpp2 option -j (C++ only) to generate C++ proxy and service objects.
4343 The auto-generated files include documented inferfaces. Compile with
4344 soapC.cpp and link with -lgsoap++, or alternatively compile stdsoap2.cpp.
4346 - Without soapcpp2 option -j: client-side uses the auto-generated
4347 soapClient.cpp and soapC.cpp (or C versions of those). Compile and link with
4348 -lgsoap++ (-lgsoap for C), or alternatively compile stdsoap2.cpp
4351 - Without soapcpp2 option -j: server-side uses the auto-generated
4352 soapServer.cpp and soapC.cpp (or C versions of those). Compile and link with
4353 -lgsoap++ (-lgsoap for C), or alternatively compile stdsoap2.cpp (stdsoap2.c
4356 - Use `soap_new()` or `soap_new1(int flags)` to allocate and initialize a
4357 heap-allocated context with or without flags. Delete this context with
4358 `soap_free(struct soap*)`, but only after `soap_destroy(struct soap*)` and
4359 `soap_end(struct soap*)`.
4361 - Use `soap_init(struct *soap)` or `soap_init1(struct soap*, int flags)` to
4362 initialize a stack-allocated context with or without flags. End the use of
4363 this context with `soap_done(struct soap*)`, but only after
4364 `soap_destroy(struct soap*)` and `soap_end(struct soap*)`.
4366 Additional notes with respect to the wsdl2h and soapcpp2 tools:
4368 - Nested classes, structs, and unions in a gSOAP header file are unnested by
4371 - Use `#import "file.h"` instead of `#include` to import other header files in
4372 a gSOAP header file for soapcpp2. The `#include`, `#define`, and `#pragma`
4373 are accepted by soapcpp2, but are moved to the very start of the generated
4374 code for the C/C++ compiler to include before all generated definitions.
4375 Often it is useful to add an `#include` with a [volatile type](#toxsd9-2)
4376 that includes the actual type declaration, and to ensure transient types are
4377 declared when these are used in a data binding interface declared in a gSOAP
4378 header file for soapcpp2.
4380 - To remove any SOAP-specific bindings, use soapcpp2 option `-0`.
4382 - A gSOAP header file for soapcpp2 should not include any code statements, only
4383 data type declarations. This includes constructor initialization lists that are
4384 not permitted. Use member initializations instead.
4386 - C++ namespaces are supported. Use wsdl2h option `-qname`. Or add a `namespace
4387 name { ... }` to the header file, but the `{ ... }` MUST cover the entire
4388 header file content from begin to end.
4390 - Optional XML DOM support can be used to store mixed content or literal XML
4391 content. Otherwise, mixed content may be lost. Use wsdl2h option `-d` for
4392 XML DOM support and compile and link with `dom.c` or `dom.cpp`. For details,
4393 see [XML DOM and XPath](http://www.genivia.com/doc/dom/html).
4395 Removing SOAP namespaces from XML payloads {#nsmap}
4396 ==========================================
4398 The soapcpp2 tool generates a `.nsmap` file that includes two bindings for SOAP
4399 namespaces. We can remove all SOAP namespaces (and SOAP processing logic) with
4400 soapcpp2 option `-0` or by simply setting the two entries to NULL:
4402 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
4403 struct Namespace namespaces[] =
4405 {"SOAP-ENV", NULL, NULL, NULL},
4406 {"SOAP-ENC", NULL, NULL, NULL},
4409 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4411 Note that once the `.nsmap` is generated, you can copy-paste the content into
4412 your project code. However, if we rerun wsdl2h on updated WSDL/XSD files or
4413 `typemap.dat` declarations then we need to use the updated table.
4415 In cases that no XML namespaces are used at all, for example with
4416 [XML-RPC](http://www.genivia.com/doc/xml-rpc-json/html), you may use an empty
4419 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
4420 struct Namespace namespaces[] = {{NULL,NULL,NULL,NULL}};
4421 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4423 However, beware that any built-in xsi attributes that are rendered will lack
4424 the proper namespace binding. At least we suggest to use `SOAP_XML_NOTYPE` for
4427 Examples {#examples}
4430 Select the project files below to peruse the source code examples.
4435 - `address.xsd` Address book schema
4436 - `address.cpp` Address book app (reads/writes address.xml file)
4437 - `addresstypemap.dat` Schema namespace prefix name preference for wsdl2h
4438 - `graph.h` Graph data binding (tree, digraph, cyclic graph)
4439 - `graph.cpp` Test graph serialization as tree, digraph, and cyclic
4444 - `address.h` gSOAP-specific data binding definitions from address.xsd
4445 - `addressStub.h` C++ data binding definitions
4446 - `addressH.h` Serializers
4447 - `addressC.cpp` Serializers
4448 - `address.xml` Address book data generated by address app
4449 - `graphStub.h` C++ data binding definitions
4450 - `graphH.h` Serializers
4451 - `graphC.cpp` Serializers
4452 - `g.xsd` XSD schema with `g:Graph` complexType
4453 - `g.nsmap` xmlns bindings namespace mapping table
4458 Building the AddressBook example:
4460 wsdl2h -g -t addresstypemap.dat address.xsd
4461 soapcpp2 -0 -CS -I../../import -p address address.h
4462 c++ -I../.. address.cpp addressC.cpp -o address -lgsoap++
4464 Option `-g` produces bindings for global (root) elements in addition to types.
4465 In this case the root element `a:address-book` is bound to `_a__address_book`.
4466 The complexType `a:address` is bound to class `a__address`, which is also the
4467 type of `_a__address_book`. This option is not required, but allows you to use
4468 global element tag names when referring to their serializers, instead of their
4469 type name. Option `-0` removes the SOAP protocol. Options `-C` and `-S`
4470 removes client and server code generation. Option `-p` renames the output
4471 `soap` files to `address` files.
4473 See the `address.cpp` implementation and [related pages](pages.html).
4475 The `addresstypemap.dat` file specifies the XML namespace prefix for the
4478 # Bind the address book schema namespace to prefix 'a'
4480 a = "urn:address-book-example"
4482 # By default the xsd:dateTime schema type is translated to time_t
4483 # To map xsd:dateTime to struct tm, enable the following line:
4485 # xsd__dateTime = #import "../../custom/struct_tm.h"
4487 # ... and compile/link with custom/struct_tm.c
4489 The DOB field is a `xsd:dateTime`, which is bound to `time_t` by default. To
4490 change this to `struct tm`, enable the import of the `xsd__dateTime` custom
4491 serializer by uncommenting the definition of `xsd__dateTime` in
4492 `addresstypemap.dat`. Then change `soap_dateTime2s` to `soap_xsd__dateTime2s`
4495 Building the graph serialization example:
4497 soapcpp2 -CS -I../../import -p graph graph.h
4498 c++ -I../.. graph.cpp graphC.cpp -o graph -lgsoap++
4500 To compile without using the `libgsoap++` library: simply compile
4501 `stdsoap2.cpp` together with the above.
4506 To execute the AddressBook example:
4510 To execute the Graph serialization example: