2 C and C++ XML Data Bindings {#mainpage}
3 ===========================
10 This article presents a detailed overview of the gSOAP XML data bindings for C
11 and C++. The XML data bindings for C and C++ are extensively used with gSOAP
12 Web services to serialize C and C++ data in XML as part of the SOAP/XML Web
13 services payloads. Also REST XML with gSOAP relies on XML serialization of C
14 and C++ data via XML data bindings.
16 The major advantage of XML data bindings is that your application data is
17 always **type safe** in C and C++ by binding XML schema types to C/C++ types.
18 So integers in XML are bound to C integers, strings in XML are bound to C or
19 C++ strings, complex types in XML are bound to C structs or C++ classes, and so
20 on. The structured data you create and accept will fit the data model and is
21 **static type safe**. In other words, by leveraging strong typing in C/C++,
22 your XML data meets **XML schema validation requirements** and satisfies **XML
23 interoperability requirements**.
25 In fact, gSOAP data bindings are more powerful than simply representing C/C++
26 data in XML. The gSOAP tools implement true and tested **structure-preserving
27 serialization** of C/C++ data in XML, including the serialization of cyclic
28 graph structures with id-ref XML attributes. The gSOAP tools also generate
29 routines for deep copying and deep deletion of C/C++ data structures to
30 simplify memory management. In addition, C/C++ structures are deserialized
31 into managed memory, managed by the gSOAP `soap` context.
33 At the end of this article two examples are given to illustrate the application
34 of XML data bindings. The first simple example <i>`address.cpp`</i> shows how to use
35 wsdl2h to bind an XML schema to C++. The C++ application reads and writes an
36 XML file into and from a C++ "address book" data structure as a simple example.
37 The C++ data structure is an STL vector of address objects. The second example
38 <i>`graph.cpp`</i> shows how C++ data can be accurately serialized as a tree, digraph,
39 and cyclic graph in XML. The digraph and cyclic graph serialization rules
40 implement SOAP 1.1/1.2 multi-ref encoding with id-ref attributes to link
41 elements through IDREF XML references, creating a an XML graph with pointers to
42 XML nodes that preserves the structural integrity of the serialized C++ data.
44 These examples demonstrate XML data bindings only for relatively simple data
45 structures and types. The gSOAP tools support more than just these type of
46 structures to serialize in XML. There are practically no limits to the
47 serialization of C and C++ data types in XML.
49 Also the support for XML schema (XSD) components is unlimited. The wsdl2h tool
50 maps schemas to C and C++ using built-in intuitive mapping rules, while
51 allowing the mappings to be customized using a <i>`typemap.dat`</i> file with mapping
52 instructions for wsdl2h.
54 The information in this article is applicable to gSOAP 2.8.26 and greater that
55 support C++11 features. However, C++11 is not required. The material and the
56 examples in this article use plain C and C++, until the point where we
57 introduce C++11 smart pointers and scoped enumerations. While most of the
58 examples in this article are given in C++, the concepts also apply to C with
59 the exception of containers, smart pointers, classes and their methods. None
60 of these exceptions limit the use of the gSOAP tools for C in any way.
62 The data binding concepts described in this article were first envisioned in
63 1999 by Prof. Robert van Engelen at the Florida State University. An
64 implementation was created in 2000, named "stub/skeleton compiler". The first
65 articles on its successor version "gSOAP" appeared in 2002. The principle of
66 mapping XSD components to C/C++ types and vice versa is now widely adopted in
67 systems and programming languages, including Java web services and by C# WCF.
69 We continue to be committed to our goal to empower C/C++ developers with
70 powerful autocoding tools for XML. Our commitment started in the very early
71 days of SOAP by actively participating in
72 [SOAP interoperability testing](http://www.whitemesa.com/interop.htm),
73 participating in the development and testing of the
74 [W3C XML Schema Patterns for Databinding Interoperability](http://www.w3.org/2002/ws/databinding),
75 and continues by contributing to the development of
76 [OASIS open standards](https://www.oasis-open.org) in partnership with leading
77 IT companies in the world.
79 🔝 [Back to table of contents](#)
81 Notational Conventions {#conventions}
82 ======================
84 The typographical conventions used by this document are:
86 * `Courier` denotes C and C++ source code.
88 * <i>`Courier`</i> denotes XML content, JSON content, file and path names, and URIs.
90 * <b>`Courier`</b> denotes HTTP content, text file content, and shell commands with command line options and arguments.
92 The keywords "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", "SHOULD",
93 "SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in this document are to
94 be interpreted as described in RFC-2119.
96 🔝 [Back to table of contents](#)
98 Mapping WSDL and XML schemas to C/C++ {#tocpp}
99 =====================================
101 To convert WSDL and XML schemas (XSD files) to code, we use the wsdl2h command
102 on the command line (or command prompt), after opening a terminal. The wsdl2h
103 command generates the data binding interface code that is saved to a special
104 Web services and data bindings interface header file with extension <i>`.h`</i>
105 that contains the WSDL service declarations and the data binding interface
106 declarations in a familiar C/C++ format:
108 wsdl2h [options] -o file.h ... XSD and WSDL files ...
110 This command converts WSDL and XSD files to C++ (or pure C with
111 <b>`wsdl2h -c`</b>) and saves the data binding interface to a interface header
112 file <i>`file.h`</i> that uses familiar C/C++ syntax extended with `//gsoap`
113 [directives](#directives) and annotations. Notational conventions are used in
114 the data binding interface to declare serializable C/C++ types and functions
115 for Web service operations.
117 The WSDL 1.1/2.0, SOAP 1.1/1.2, and XSD 1.0/1.1 standards are supported by the
118 gSOAP tools. In addition, the most popular WS specifications are also
119 supported, including WS-Addressing, WS-ReliableMessaging, WS-Discovery,
120 WS-Security, WS-Policy, WS-SecurityPolicy, and WS-SecureConversation.
122 This article focusses mainly on XML data bindings. XML data bindings for C/C++
123 bind XML schema types to C/C++ types. So integers in XML are bound to C
124 integers, strings in XML are bound to C or C++ strings, complex types in XML
125 are bound to C structs or C++ classes, and so on.
127 A data binding is dual, meaning supporting a two way direction for development.
128 Either you start with WSDLs and/or XML schemas that are mapped to equivalent
129 C/C++ types, or you start with C/C++ types that are mapped to XSD types.
130 Either way, the end result is that you can serialize C/C++ types in XML such
131 that your XML is an instance of XML schema(s) and is validated against these
134 This covers all of the following standard XSD components with their optional
135 attributes and properties:
137 XSD component | attributes and properties
138 -------------- | -------------------------
139 schema | targetNamespace, version, elementFormDefault, attributeFormDefault, defaultAttributes
140 attribute | name, ref, type, use, default, fixed, form, targetNamespace, wsdl:arrayType
141 element | name, ref, type, default, fixed, form, nillable, abstract, substitutionGroup, minOccurs, maxOccurs, targetNamespace
143 complexType | name, abstract, mixed, defaultAttributesApply
145 choice | minOccurs, maxOccurs
146 sequence | minOccurs, maxOccurs
147 group | name, ref, minOccurs, maxOccurs
148 attributeGroup | name, ref
149 any | minOccurs, maxOccurs
152 And also the following standard XSD directives are covered:
154 directive | description
155 ---------- | -----------
156 import | Imports a schema into the importing schema for referencing
157 include | Include schema component definitions into a schema
158 override | Override by replacing schema component definitions
159 redefine | Extend or restrict schema component definitions
160 annotation | Annotates a component
162 The XSD facets and their mappings to C/C++ are:
165 -------------- | -------
167 simpleContent | class/struct wrapper with `__item` member
168 complexContent | class/struct
169 list | `enum*` bitmask (`enum*` enumerates a bitmask up to 64 bits)
170 extension | class/struct inheritance/extension
171 restriction | `typedef` and class/struct inheritance/redeclaration
172 length | `typedef` with restricted content length annotation
173 minLength | `typedef` with restricted content length annotation
174 maxLength | `typedef` with restricted content length annotation
175 minInclusive | `typedef` with numerical value range restriction annotation
176 maxInclusive | `typedef` with numerical value range restriction annotation
177 minExclusive | `typedef` with numerical value range restriction annotation
178 maxExclusive | `typedef` with numerical value range restriction annotation
179 precision | `typedef` with pattern annotation (pattern used for output, but input is not validated)
180 scale | `typedef` with pattern annotation (pattern used for output, but input is not validated)
181 totalDigits | `typedef` with pattern annotation (pattern used for output, but input is not validated)
182 fractionDigits | `typedef` with pattern annotation (pattern used for output, but input is not validated)
183 pattern | `typedef` with pattern annotation (define `soap::fsvalidate` callback to validate patterns)
184 union | string with union of value
186 All primitive XSD types are supported, including but not limited to the
190 ---------------- | -------
191 any/anyType | `_XML` string with literal XML content (or enable DOM with wsdl2h option `-d`)
192 anyURI | string (i.e. `char*`, `wchar_t*`, `std::string`, `std::wstring`)
193 string | string (i.e. `char*`, `wchar_t*`, `std::string`, `std::wstring`)
194 boolean | `bool` (C++) or `enum xsd__boolean` (C)
195 byte | `char` (i.e. `int8_t`)
196 short | `short` (i.e. `int16_t`)
197 int | `int` (i.e. `int32_t`)
198 long | `LONG64` (i.e. `long long` and `int64_t`)
199 unsignedByte | `unsigned char` (i.e. `uint8_t`)
200 unsignedShort | `unsigned short` (i.e. `uint16_t`)
201 unsignedInt | `unsigned int` (i.e. `uint32_t`)
202 unsignedLong | `ULONG64` (i.e. `unsigned long long` and `uint64_t`)
205 integer | string or `#import "custom/int128.h"` to use 128 bit `xsd__integer`
206 decimal | string or `#import "custom/long_double.h"` to use `long double`
207 precisionDecimal | string
208 duration | string or `#import "custom/duration.h"` to use 64 bit `xsd__duration`
209 dateTime | `time_t` or `#import "custom/struct_tm.h"` to use `struct tm` for `xsd__dateTime`
210 time | string or `#import "custom/long_time.h"` to use 64 bit `xsd__time`
211 date | string or `#import "custom/struct_tm_date.h"` to use `struct tm` for `xsd__date`
212 hexBinary | special class/struct `xsd__hexBinary`
213 base64Binary | special class/struct `xsd__base64Binary`
214 QName | `_QName` string (URI normalization rules are applied)
216 All other primitive XSD types not listed above are mapped to strings, by
217 wsdl2h generating a `typedef` to string for these types. For example,
218 <i>`xsd:token`</i> is bound to a C++ or C string:
221 typedef std::string xsd__token; // C++
222 typedef char *xsd__token; // C (wsdl2h option -c)
225 This associates a compatible value space to the type with the appropriate XSD
226 type name used by the soapcpp2-generated serializers.
228 It is possible to remap types by adding the appropriate mapping rules to
229 <i>`typemap.dat`</i> as we will explain in more detail in the next section.
231 Imported custom serializers are intended to extend the C/C++ type bindings when
232 the default binding to string is not satisfactory to your taste and if the
233 target platform supports these C/C++ types. To add custom serializers to
234 <i>`typemap.dat`</i> for wsdl2h, see [adding custom serializers](#custom) below.
236 🔝 [Back to table of contents](#)
238 Using typemap.dat to customize data bindings {#typemap}
239 ============================================
241 Use a <i>`typemap.dat`</i> file to redefine namespace prefixes and to customize type
242 bindings for the the generated header files produced by the wsdl2h tool. The
243 <i>`typemap.dat`</i> is the default file processed by wsdl2h. Use <b>`wsdl2h -tfile.dat`</b>
244 option <b>`-tfile.dat`</b> to specify a different mapping file <i>`file.dat`</i>.
246 Declarations in <i>`typemap.dat`</i> can be broken up over multiple lines by
247 continuing on the next line by ending each line to be continued with a
248 backslash <b>`\`</b>. The limit is 4095 characters per line, whether the line is
251 🔝 [Back to table of contents](#)
253 XML namespace bindings {#typemap1}
254 ----------------------
256 The wsdl2h tool generates C/C++ type declarations that use `ns1`, `ns2`, etc.
257 as schema-binding URI prefixes. These default prefixes are generated somewhat
258 arbitrarily for each schema targetNamespace URI, meaning that their ordering
259 may change depending on the WSDL and XSD order of processing with wsdl2h.
261 Therefore, it is **strongly recommended** to declare your own prefix for each
262 schema URI in <i>`typemap.dat`</i> to reduce maintaince effort of your code. This
263 is more robust when anticipating possible changes of the schema(s) and/or the
264 binding URI(s) and/or the tooling algorithms.
266 The first and foremost important thing to do is to define prefix-URI bindings
267 for our C/C++ code by adding the following line(s) to our <i>`typemap.dat`</i> or make
268 a copy of this file and add the line(s) that bind our choice of prefix name to
273 For example, to use `g` as a prefix for the "urn:graph" XML namespace:
277 This produces `g__name` C/C++ type names that are bound to the "urn:graph"
278 schema by association of `g` to the generated C/C++ types.
280 This means that <i>`<g:name xmlns:g="urn:graph">`</i> is parsed as an instance of a
281 `g__name` C/C++ type. Also <i>`<x:name xmlns:x="urn:graph">`</i> parses as an
282 instance of `g__name`, because the prefix <i>`x`</i> has the same URI value
283 <i>`urn:graph`</i>. Prefixes in XML have local scopes (like variables in a block).
285 The first run of wsdl2h will reveal the XML namespace URIs, so you do not need
286 to search WSDLs and XSD files for all of the target namespaces. Just copy them
287 from the generated header file after the first run into <i>`typemap.dat`</i> for
290 @note Only define a namespace prefix once in <i>`typemap.dat`</i>. That is, do not
291 use the same prefix for multiple XML namespace URIs. This is to avoid
292 namespace conflicts that may cause failed builds and failures in XML parsing
293 and XML schema validation.
295 🔝 [Back to table of contents](#)
297 XSD type bindings {#typemap2}
300 Custom C/C++ type bindings can be declared in <i>`typemap.dat`</i> to associate C/C++
301 types with specific schema types. These type bindings have four parts:
303 prefix__type = declaration | use | ptruse
307 - <b>`prefix__type`</b> is the schema type to be customized (the <b>`prefix__type`</b> name
308 uses the common double underscore naming convention);
310 - <b>`declaration`</b> declares the C/C++ type in the wsdl2h-generated header file.
311 This part can be empty if no explicit declaration is needed;
313 - <b>`use`</b> is an optional part that specifies how the C/C++ type is used in the
314 code. When omitted, it is the same as <b>`prefix__type`</b>;
316 - <b>`ptruse`</b> is an optional part that specifies how the type is used as a pointer
317 type. By default it is the <b>`use`</b> type name with a <b>`*`</b> or C++11
318 <b>`std::shared_ptr<type>`</b> when enabled (see further below). If <b>`use`</b> is already a
319 pointer type by the presence of a <b>`*`</b> in the <b>`use`</b> part, then the default
320 <b>`ptruse`</b> type is the same as the <b>`use`</b> type (that is, no double
321 pointers <b>`**`</b> will be created in this case).
323 For example, to map <i>`xsd:duration`</i> to a `long long` (`LONG64`) type that holds
324 millisecond duration values, we can use the custom serializer declared in
325 <i>`gsoap/custom/duration.h`</i> by adding the following line to <i>`typemap.dat`</i>:
327 xsd__duration = #import "custom/duration.h"
329 Here, we omitted the second and third parts, because `xsd__duration` is the
330 name that wsdl2h uses for this type in our generated code so we should leave
331 the <b>`use`</b> part unspecified. The third part is omitted to let wsdl2h use
332 `xsd__duration *` for pointers or `std::shared_ptr<xsd__duration>` if smart
333 pointers are enabled.
335 To map <i>`xsd:string`</i> to `wchar_t*` wide strings for C source code output:
337 xsd__string = | wchar_t* | wchar_t*
339 For C++ we can use the `std::wstring` wide string:
341 xsd__string = | std::wstring
343 Note that the first part is empty, because these types do not require a
344 declaration. A <b>`ptruse`</b> part is also defined for `wchar_t*`, but this
345 is actually needed because the wsdl2h tool recognizes that the <b>`use`</b>
346 part `wchar_t*` is already a pointer. By contrast, when using 8-bit strings,
347 it is recommended to use the `SOAP_C_UTFSTRING` flag to enable UTF-8 formatted
350 When the auto-generated declaration should be preserved but the <b>`use`</b> or
351 <b>`ptruse`</b> parts replaced, then we use an ellipsis for the declaration part:
353 prefix__type = ... | use | ptruse
355 This is useful to map schema polymorphic types to C types for example, where we
356 need to be able to both handle a base type and its extensions as per schema
357 extensibility. Say we have a base type called <i>`ns:base`</i> that is extended, then
358 we can remap this to a C type that permits referening the extended types via a
361 ns__base = ... | int __type_base; void*
363 such that `__type_base` and `void*` will be used to (de)serialize any data
364 type, including base and its derived types. The `__type_base` integer is set
365 to a `SOAP_TYPE_T` value to indicate what type of data the `void*` pointer
368 🔝 [Back to table of contents](#)
370 Custom serializers for XSD types {#custom}
371 --------------------------------
373 In the previous part we saw how a custom serializer is used to bind
374 <i>`xsd:duration`</i> to a `long long` (`LONG64` or `int64_t`) type to store millisecond
377 xsd__duration = #import "custom/duration.h"
379 The `xsd__duration` type is an alias of `long long` (`LONG64` or `int64_t`).
381 While wsdl2h will use this binding declared in <i>`typemap.dat`</i>
382 automatically, you will also need to compile <i>`gsoap/custom/duration.c`</i>.
383 Each custom serializer has an interface header file to be imported into another
384 interface header file that declares the custom type for soapcpp2 and a
385 serializer implementation file written in C, which should be compiled with the
386 application. You can compile these in C++ (rename files to <i>`.cpp`</i> if
389 A custom serializer is declared in an interface header file for soapcpp2 using
390 `extern typedef`. The typedef name declared is serializable, whereas the
391 type on which it is based is not serializable. This declaration can be
392 combined with `volatile` when the type should not be redeclared, see
393 [volatile classes and structs](#toxsd9-2). For example, the custom serializer
394 for `struct tm` is the type `xsd__datetime` declared as follows in
395 `gsoap/custom/struct_tm.h`:
398 extern typedef volatile struct tm
400 int tm_sec; ///< seconds (0 - 60)
401 int tm_min; ///< minutes (0 - 59)
402 int tm_hour; ///< hours (0 - 23)
403 int tm_mday; ///< day of month (1 - 31)
404 int tm_mon; ///< month of year (0 - 11)
405 int tm_year; ///< year - 1900
406 int tm_wday; ///< day of week (Sunday = 0) (NOT USED)
407 int tm_yday; ///< day of year (0 - 365) (NOT USED)
408 int tm_isdst; ///< is summer time in effect?
409 char* tm_zone; ///< abbreviation of timezone (NOT USED)
413 Another example is `xsd__duration` as a custom serializer for the C++11 type
414 `std::chrono::nanoseconds`:
417 extern typedef class std::chrono::nanoseconds xsd__duration;
420 Next, we present all pre-defined custom serializers that are available to you.
422 🔝 [Back to table of contents](#)
424 ### xsd:integer {#custom-1}
426 The wsdl2h tool maps <i>`xsd:integer`</i> to a string by default. To map <i>`xsd:integer`</i> to
427 the 128 bit big int type `__int128_t`:
429 xsd__integer = #import "custom/int128.h"
431 The `xsd__integer` type is an alias of `__int128_t`.
433 @warning Beware that the <i>`xsd:integer`</i> value space of integers is in principle
434 unbounded and values can be of arbitrary length. A value range fault
435 `SOAP_TYPE` (value exceeds native representation) or `SOAP_LENGTH` (value
436 exceeds range bounds) will be thrown by the deserializer if the value is out of
439 Other XSD integer types that are restrictions of <i>`xsd:integer`</i>, are
440 <i>`xsd:nonNegativeInteger`</i> and <i>`xsd:nonPositiveInteger`</i>, which are further restricted
441 by <i>`xsd:positiveInteger`</i> and <i>`xsd:negativeInteger`</i>. To bind these types to
442 `__int128_t` add the following definitions to <i>`typemap.dat`</i>:
444 xsd__nonNegativeInteger = typedef xsd__integer xsd__nonNegativeInteger 0 : ;
445 xsd__nonPositiveInteger = typedef xsd__integer xsd__nonPositiveInteger : 0 ;
446 xsd__positiveInteger = typedef xsd__integer xsd__positiveInteger 1 : ;
447 xsd__negativeInteger = typedef xsd__integer xsd__negativeInteger : -1 ;
449 Or simply uncomment these definitions in <i>`typemap.dat`</i> when you are using the
450 latest gSOAP releases.
452 @note If `__int128_t` 128 bit integers are not supported on your platform and if it
453 is certain that <i>`xsd:integer`</i> values are within 64 bit value bounds for your
454 application's use, then you can map this type to `LONG64`:
456 xsd__integer = typedef LONG64 xsd__integer;
458 @note Again, a value range fault `SOAP_TYPE` or `SOAP_LENGTH` will be thrown by
459 the deserializer if the value is out of range.
461 After running wsdl2h and soapcpp2, compile <i>`gsoap/custom/int128.c`</i> with your project.
463 @see Section [numerical types](#toxsd5).
465 🔝 [Back to table of contents](#)
467 ### xsd:decimal {#custom-2}
469 The wsdl2h tool maps <i>`xsd:decimal`</i> to a string by default. To map <i>`xsd:decimal`</i> to
470 extended precision floating point:
472 xsd__decimal = #import "custom/long_double.h" | long double
474 By contrast to all other custom serializers, this serializer enables `long
475 double` natively without requiring a new binding name (`xsd__decimal` is NOT
478 If your system supports <i>`quadmath.h`</i> quadruple precision floating point
479 `__float128`, you can map <i>`xsd:decimal`</i> to `xsd__decimal` that is an alias of
482 xsd__decimal = #import "custom/float128.h"
484 @warning Beware that <i>`xsd:decimal`</i> is in principle a decimal value with arbitraty
485 lengths. A value range fault `SOAP_TYPE` will be thrown by the deserializer if
486 the value is out of range.
488 In the XML payload the special values <i>`INF`</i>, <i>`-INF`</i>, <i>`NaN`</i>
489 represent plus or minus infinity and not-a-number, respectively.
491 After running wsdl2h and soapcpp2, compile <i>`gsoap/custom/long_double.c`</i> with your
494 @see Section [numerical types](#toxsd5).
496 🔝 [Back to table of contents](#)
498 ### xsd:dateTime {#custom-3}
500 The wsdl2h tool maps <i>`xsd:dateTime`</i> to `time_t` by default.
502 The trouble with `time_t` when represented as 32 bit `long` integers is that it
503 is limited to dates between 1970 and 2038. A 64 bit `time_t` is safe to use if
504 the target platform supports it, but lack of 64 bit `time_t` portability may
505 still cause date range issues.
507 For this reason `struct tm` should be used to represent wider date ranges. This
508 custom serializer avoids using date and time information in `time_t`. You get
509 the raw date and time information. You only lose the day of the week
510 information. It is always Sunday (`tm_wday=0`).
512 To map <i>`xsd:dateTime`</i> to `xsd__dateTime` which is an alias of `struct tm`:
514 xsd__dateTime = #import "custom/struct_tm.h"
516 If the limited date range of `time_t` is not a problem but you want to increase
517 the time precision with fractional seconds, then we suggest to map <i>`xsd:dateTime`</i>
520 xsd__dateTime = #import "custom/struct_timeval.h"
522 If the limited date range of `time_t` is not a problem but you want to use the
523 C++11 time point type `std::chrono::system_clock::time_point` (which internally
526 xsd__dateTime = #import "custom/chrono_time_point.h"
528 Again, we should make sure that the dates will not exceed the date range when
529 using the default `time_t` binding for <i>`xsd:dateTime`</i> or when binding
530 <i>`xsd:dateTime`</i> to `struct timeval` or to `std::chrono::system_clock::time_point`.
531 These are safe to use in applications that use <i>`xsd:dateTime`</i> to record date
532 stamps within a given window. Otherwise, we recommend the `struct tm` custom
535 After running wsdl2h and soapcpp2, compile <i>`gsoap/custom/struct_tm.c`</i> with your
538 You could even map <i>`xsd:dateTime`</i> to a plain string (use `char*` with C and
539 `std::string` with C++). For example:
541 xsd__dateTime = | char*
543 @see Section [date and time types](#toxsd7).
545 🔝 [Back to table of contents](#)
547 ### xsd:date {#custom-4}
549 The wsdl2h tool maps <i>`xsd:date`</i> to a string by default. We can map <i>`xsd:date`</i> to
552 xsd__date = #import "custom/struct_tm_date.h"
554 The `xsd__date` type is an alias of `struct tm`. The serializer ignores the
555 time part and the deserializer only populates the date part of the struct,
556 setting the time to 00:00:00. There is no unreasonable limit on the date range
557 because the year field is stored as an integer (`int`).
559 After running wsdl2h and soapcpp2, compile <i>`gsoap/custom/struct_tm_date.c`</i> with your
562 @see Section [date and time types](#toxsd7).
564 🔝 [Back to table of contents](#)
566 ### xsd:time {#custom-5}
568 The wsdl2h tool maps <i>`xsd:time`</i> to a string by default. We can map <i>`xsd:time`</i> to
569 an `unsigned long long` (`ULONG64` or `uint64_t`) integer with microsecond time
572 xsd__time = #import "custom/long_time.h"
574 This type represents 00:00:00.000000 to 23:59:59.999999, from `0` to an upper
575 bound of `86399999999`. A microsecond resolution means that a 1 second
576 increment requires an increment of 1000000 in the integer value. The serializer
577 adds a UTC time zone.
579 After running wsdl2h and soapcpp2, compile <i>`gsoap/custom/long_time.c`</i> with your
582 @see Section [date and time types](#toxsd7).
584 🔝 [Back to table of contents](#)
586 ### xsd:duration {#custom-6}
588 The wsdl2h tool maps <i>`xsd:duration`</i> to a string by default, unless <i>`xsd:duration`</i>
589 is mapped to a `long long` (`LONG64` or `int64_t`) type with with millisecond
590 (ms) time duration precision:
592 xsd__duration = #import "custom/duration.h"
594 The `xsd__duration` type is a 64 bit signed integer that can represent
595 106,751,991,167 days forwards (positive) and backwards (negative) in time in
596 increments of 1 ms (1/1000 of a second).
598 Rescaling of the duration value by may be needed when adding the duration value
599 to a `time_t` value, because `time_t` may or may not have a seconds resolution,
600 depending on the platform and possible changes to `time_t`.
602 Rescaling is done automatically when you add a C++11 `std::chrono::nanoseconds`
603 value to a `std::chrono::system_clock::time_point` value. To use
604 `std::chrono::nanoseconds` as <i>`xsd:duration`</i>:
606 xsd__duration = #import "custom/chrono_duration.h"
608 This type can represent 384,307,168 days (2^63 nanoseconds) forwards and
609 backwards in time in increments of 1 ns (1/1,000,000,000 of a second).
611 Certain observations with respect to receiving durations in years and months
612 apply to both of these serializer decoders for <i>`xsd:duration`</i>.
614 After running wsdl2h and soapcpp2, compile <i>`gsoap/custom/duration.c`</i> with your
617 @see Section [time duration types](#toxsd8).
619 🔝 [Back to table of contents](#)
621 Custom Qt serializers for XSD types {#qt}
622 -----------------------------------
624 The gSOAP distribution includes several custom serializers for Qt types. Also
625 Qt container classes are supported, see
626 [the built-in typemap.dat variables $CONTAINER, $POINTER and $SIZE](#typemap5).
628 This feature requires gSOAP 2.8.34 or higher and Qt 4.8 or higher.
630 Each Qt custom serializer has an interface header file for soapcpp2 and a C++
631 implementation file to be compiled with your project.
633 Other Qt primitive types that are Qt `typedef`s of C/C++ types do not require a
636 🔝 [Back to table of contents](#)
638 ### xsd:string {#qt-1}
640 To use Qt strings instead of C++ strings, add the following definition to
641 <i>`typemap.dat`</i>:
643 xsd__string = #import "custom/qstring.h"
645 After running wsdl2h and soapcpp2, compile <i>`gsoap/custom/qstring.cpp`</i> with your
648 🔝 [Back to table of contents](#)
650 ### xsd:base64Binary {#qt-2}
652 To use Qt byte arrays for <i>`xsd:base64Binary`</i> instead of the
653 `xsd__base64Binary` class, add the following definition to <i>`typemap.dat`</i>:
655 xsd__base64Binary = #import "custom/qbytearray_base64.h"
657 After running wsdl2h and soapcpp2, compile <i>`gsoap/custom/qbytearray_base64.cpp`</i> with
660 🔝 [Back to table of contents](#)
662 ### xsd:hexBinary {#qt-3}
664 To use Qt byte arrays for <i>`xsd:hexBinary`</i> instead of the `xsd__base64Binary`
665 class, add the following definition to <i>`typemap.dat`</i>:
667 xsd__hexBinary = #import "custom/qbytearray_hex.h"
669 After running wsdl2h and soapcpp2, compile <i>`gsoap/custom/qbytearray_hex.cpp`</i> with
672 🔝 [Back to table of contents](#)
674 ### xsd:dateTime {#qt-4}
676 To use Qt QDateTime for <i>`xsd:dateTime`</i>, add the following definition to
677 <i>`typemap.dat`</i>:
679 xsd__dateTime = #import "custom/datetime.h"
681 After running wsdl2h and soapcpp2, compile <i>`gsoap/custom/qdatetime.cpp`</i> with
684 🔝 [Back to table of contents](#)
688 To use Qt QDate for <i>`xsd:date`</i>, add the following definition to
689 <i>`typemap.dat`</i>:
691 xsd__date = #import "custom/qdate.h"
693 After running wsdl2h and soapcpp2, compile <i>`gsoap/custom/qdate.cpp`</i> with your
696 🔝 [Back to table of contents](#)
700 To use Qt QDate for <i>`xsd:time`</i>, add the following definition to
701 <i>`typemap.dat`</i>:
703 xsd__time = #import "custom/qtime.h"
705 After running wsdl2h and soapcpp2, compile <i>`gsoap/custom/qtime.cpp`</i> with your
708 🔝 [Back to table of contents](#)
710 Class/struct member additions {#typemap3}
711 -----------------------------
713 All generated classes and structs can be augmented with additional
714 members such as methods, constructors and destructors, and private members:
716 prefix__type = $ member-declaration
718 For example, we can add method declarations and private members to a class, say
719 `ns__record` as follows:
721 ns__record = $ ns__record(const ns__record &); // copy constructor
722 ns__record = $ void print(); // a print method
723 ns__record = $ private: int status; // a private member
725 Method declarations cannot include any code, because soapcpp2's input permits
726 only type declarations, not code.
728 🔝 [Back to table of contents](#)
730 Replacing XSD types by equivalent alternatives {#typemap4}
731 ----------------------------------------------
733 Type replacements can be given to replace one type entirely with another given
736 prefix__type1 == prefix__type2
738 This replaces all `prefix__type1` by `prefix__type2` in the wsdl2h output.
740 @warning Do not agressively replace types, because this can cause XML schema
741 validation to fail when a value-type mismatch is encountered in the XML input.
742 Therefore, only replace similar types with other similar types that are wider
743 (e.g. `short` by `int` and `float` by `double`).
745 🔝 [Back to table of contents](#)
747 The built-in typemap.dat variables $CONTAINER, $POINTER and $SIZE {#typemap5}
748 -----------------------------------------------------------------
750 The <i>`typemap.dat`</i> <b>`$CONTAINER`</b> variable defines the container type to use in
751 the wsdl2h-generated declarations for C++, which is `std::vector` by default.
752 For example, to use `std::list` as the container in the wsdl2h-generated
753 declarations we add the following line to <i>`typemap.dat`</i>:
755 $CONTAINER = std::list
757 Also a Qt container can be used instead of the default `std::vector`, for
765 To remove containers, use <b>`wsdl2h -s`</b>. This also removes `std::string`,
766 but you can re-introduce `std::string` with
767 <b>`xsd__string = | std::string`</b> in <i>`typemap.dat`</i>.
769 The <i>`typemap.dat`</i> <b>`$POINTER`</b> variable defines the smart pointer to use in the
770 wsdl2h-generated declarations for C++, which replaces the use of `*` pointers.
773 $POINTER = std::shared_ptr
775 Not all pointers in the generated output are replaced by smart pointers by
776 wsdl2h, such as pointers as union members and pointers as struct/class members
777 that point to arrays of values.
779 @note The standard smart pointer `std::shared_ptr` is generally safe to use.
780 Other smart pointers such as `std::unique_ptr` and `std::auto_ptr` may cause
781 compile-time errors when classes have smart pointer members but no copy
782 constructor (a default copy constructor). A copy constructor is required for
783 non-shared smart pointer copying or swapping.
785 Alternatives to `std::shared_ptr` of the form `NAMESPACE::shared_ptr` can be
786 assigned to <b>`$POINTER`</b> when the namespace `NAMESPACE` also implements
787 `NAMESPACE::make_shared` and when the shared pointer class provides `reset()`
788 and`get()` methods and the dereference operator. For example Boost
792 #include <boost/shared_ptr.hpp>
794 $POINTER = boost::shared_ptr
796 The user-defined content between <b>`[`</b> and <b>`]`</b> ensures that we include the Boost
797 header files that are needed to support `boost::shared_ptr` and
798 `boost::make_shared`.
800 The variable <b>`$SIZE`</b> defines the type of array sizes, which is `int` by
801 default. For example, to change array size types to `size_t`:
805 Permissible types are `int` and `size_t`. This variable does not affect the
806 size of dynamic arrays, `xsd__hexBinary` and `xsd__base64Binary` types, which
809 🔝 [Back to table of contents](#)
811 User-defined content {#typemap6}
814 Any other content to be generated by wsdl2h can be included in <i>`typemap.dat`</i> by
815 enclosing it within brackets <b>`[`</b> and <b>`]`</b> anywhere in the <i>`typemap.dat`</i> file.
816 Each of the two brackets must appear at the start of a new line.
818 For example, we can add an `#import "wsa5.h"` to the wsdl2h-generated output as
822 #import "import/wsa5.h"
825 which emits the `#import "import/wsa5.h"` literally at the start of the
826 wsdl2h-generated header file.
828 🔝 [Back to table of contents](#)
830 Mapping C/C++ to XML schema {#toxsd}
831 ===========================
833 The soapcpp2 command generates the data binding implementation code from a data
834 binding interface <i>`file.h`</i>:
836 soapcpp2 [options] file.h
838 where <i>`file.h`</i> is a interface header file that declares the XML data
839 binding interface. The <i>`file.h`</i> is typically generated by wsdl2h, but
840 you can also declare one yourself. If so, add `//gsoap`
841 [directives](#directives) and declare in this file all our C/C++ types you want
844 You can also declare functions that will be converted to Web service operations
845 by soapcpp2. Global function declarations define service operations, which are
849 int prefix__func(arg1, arg2, ..., argn, result);
852 where `arg1`, `arg2`, ..., `argn` are formal argument declarations of the input
853 and `result` is a formal argument for the output, which must be a pointer or
854 reference to the result object to be populated. More information on declaring
855 and implementing service operation functions can be found in the
856 [gSOAP user guide.](../../guide/html/index.html)
858 🔝 [Back to table of contents](#)
860 Overview of serializable C/C++ types {#toxsd1}
861 ------------------------------------
863 The following C/C++ types are supported by soapcpp2 and mapped to XSD types
864 and constructs. See the subsections below for more details or follow the links.
866 🔝 [Back to table of contents](#)
868 ### List of Boolean types
871 ----------------------------- | -----
873 `enum xsd__boolean` | C alternative to C++ `bool` with `false_` and `true_`
875 @see Section [C++ bool and C alternative](#toxsd3).
877 🔝 [Back to table of contents](#)
879 ### List of enumeration and bitmask types
881 Enumeration Type | Notes
882 ----------------------------- | -----
884 `enum class` | C++11 scoped enumeration, requires `soapcpp2 -c++11`
885 `enum*` | a bitmask that enumerates values 1, 2, 4, 8, ...
886 `enum* class` | C++11 scoped enumeration bitmask, requires `soapcpp2 -c++11`
888 @see Section [enumerations and bitmasks](#toxsd4).
890 🔝 [Back to table of contents](#)
892 ### List of numerical types
894 Numerical Type | Notes
895 ----------------------------- | -----
897 `short` | 16 bit integer
898 `int` | 32 bit integer
899 `long` | 32 bit integer
900 `LONG64` | 64 bit integer
901 `xsd__integer` | 128 bit integer, use `#import "custom/int128.h"`
902 `long long` | same as `LONG64`
903 `unsigned char` | unsigned byte
904 `unsigned short` | unsigned 16 bit integer
905 `unsigned int` | unsigned 32 bit integer
906 `unsigned long` | unsigned 32 bit integer
907 `ULONG64` | unsigned 64 bit integer
908 `unsigned long long` | same as `ULONG64`
909 `int8_t` | same as `char`
910 `int16_t` | same as `short`
911 `int32_t` | same as `int`
912 `int64_t` | same as `LONG64`
913 `uint8_t` | same as `unsigned char`
914 `uint16_t` | same as `unsigned short`
915 `uint32_t` | same as `unsigned int`
916 `uint64_t` | same as `ULONG64`
917 `size_t` | transient type (not serializable)
918 `float` | 32 bit float
919 `double` | 64 bit float
920 `long double` | extended precision float, use `#import "custom/long_double.h"`
921 `xsd__decimal` | `quadmath.h` library 128 bit quadruple precision float, use `#import "custom/float128.h"`
922 `typedef` | declares a type name, with optional value range and string length bounds
924 @see Section [numerical types](#toxsd5).
926 🔝 [Back to table of contents](#)
928 ### List of string types
931 ----------------------------- | -----
932 `char*` | string (may contain UTF-8 with flag `SOAP_C_UTFSTRING`)
933 `wchar_t*` | wide string
934 `std::string` | C++ string (may contain UTF-8 with flag `SOAP_C_UTFSTRING`)
935 `std::wstring` | C++ wide string
936 `char[N]` | fixed-size string, requires `soapcpp2 -b`
937 `_QName` | normalized QName content
938 `_XML` | literal XML string content with wide characters in UTF-8
939 `typedef` | declares a new string type name, may restrict string length
941 @see Section [string types](#toxsd6).
943 🔝 [Back to table of contents](#)
945 ### List of date and time types
947 Date and Time Type | Notes
948 --------------------------------------- | -----
949 `time_t` | date and time point since epoch
950 `struct tm` | date and time point, use `#import "custom/struct_tm.h"`
951 `struct tm` | date point, use `#import "custom/struct_tm_date.h"`
952 `struct timeval` | date and time point, use `#import "custom/struct_timeval.h"`
953 `unsigned long long` | time point in microseconds, use `#import "custom/long_time.h"`
954 `std::chrono::system_clock::time_point` | date and time point, use `#import "custom/chrono_time_point.h"`
956 @see Section [date and time types](#toxsd7).
958 🔝 [Back to table of contents](#)
960 ### List of time duration types
962 Time Duration Type | Notes
963 ----------------------------- | -----
964 `long long` | duration in milliseconds, use `#import "custom/duration.h"`
965 `std::chrono::nanoseconds` | duration in nanoseconds, use `#import "custom/chrono_duration.h"`
967 @see Section [time duration types](#toxsd8).
969 🔝 [Back to table of contents](#)
971 ### List of classes, structs, unions, pointers, containers, and arrays
973 Classes, Structs, and Members | Notes
974 ----------------------------- | -----
975 `class` | C++ class with single inheritance only
976 `struct` | C struct or C++ struct without inheritance
977 `std::shared_ptr<T>` | C++11 smart shared pointer
978 `std::unique_ptr<T>` | C++11 smart pointer
979 `std::auto_ptr<T>` | C++ smart pointer
980 `std::deque<T>` | use `#import "import/stldeque.h"`
981 `std::list<T>` | use `#import "import/stllist.h"`
982 `std::vector<T>` | use `#import "import/stlvector.h"`
983 `std::set<T>` | use `#import "import/stlset.h"`
984 `template<T> class` | a container with `begin()`, `end()`, `size()`, `clear()`, and `insert()` methods
985 `T*` | pointer to data of type `T`
986 `T*` | as a class or struct member: points to data of type `T` or array of `T` with member `__size`
987 `T[N]` | as a class or struct member: fixed-size array of type `T`
988 `union` | as a class or struct member: requires a variant selector member `__union`
989 `void*` | as a class or struct member: requires a `__type` member to indicate the type of object pointed to
991 @see Section [classes and structs](#toxsd9).
993 🔝 [Back to table of contents](#)
995 ### List of special classes and structs
997 Special Classes and Structs | Notes
998 ----------------------------- | -----
999 Special Array class/struct | single and multidimensional SOAP Arrays
1000 Special Wrapper class/struct | complexTypes with simpleContent, wraps `__item` member
1001 `xsd__hexBinary` | binary content
1002 `xsd__base64Binary` | binary content and optional DIME/MIME/MTOM attachments
1003 `xsd__anyType` | DOM elements, use `#import "dom.h"`
1004 `@xsd__anyAttribute` | DOM attributes, use `#import "dom.h"`
1006 @see Section [special classes and structs](#toxsd10).
1008 🔝 [Back to table of contents](#)
1010 Colon notation versus name prefixing with XML tag name translation {#toxsd2}
1011 ------------------------------------------------------------------
1013 To bind C/C++ type names to XSD types, a simple form of name prefixing is used
1014 by the gSOAP tools by prepending the XML namespace prefix to the C/C++ type
1015 name with a pair of undescrores. This also ensures that name clashes cannot
1016 occur when multiple WSDL and XSD files are converted to C/C++. Also, C++
1017 namespaces are not sufficiently rich to capture XML schema namespaces
1018 accurately, for example when class members are associated with schema elements
1019 defined in another XML namespace and thus the XML namespace scope of the
1020 member's name is relevant, not just its type.
1022 However, from a C/C++ centric point of view this can be cumbersome. Therefore,
1023 colon notation is an alternative to physically augmenting C/C++ names with
1026 For example, the following class uses colon notation to bind the `record` class
1027 to the <i>`urn:types`</i> schema:
1030 //gsoap ns schema namespace: urn:types
1031 class ns:record // binding 'ns:' to a type name
1035 ns:record *spouse; // using 'ns:' with the type name
1036 ns:record(); // using 'ns:' here too
1037 ~ns:record(); // and here
1041 The colon notation is stripped away by soapcpp2 when generating the data
1042 binding implementation code for our project. So the final code just uses
1043 `record` to identify this class and its constructor/destructor.
1045 When using colon notation make sure to be consistent and not use colon notation
1046 mixed with prefixed forms. The qualified name `ns:record` differs from `ns__record`,
1047 because `ns:record` is compiled to an unqualified `record` name in the source
1048 code output by the soapcpp2 tool.
1050 Colon notation also facilitates overruling the elementFormDefault and
1051 attributeFormDefault declaration that is applied to local elements and
1052 attributes, when declared as members of classes, structs, and unions. For more
1053 details, see [qualified and unqualified members](#toxsd9-6).
1055 A C/C++ identifier name (a type name, member name, function name, or parameter
1056 name) is translated to an XML tag name by the following rules:
1058 - Two leading underscores indicates that the identifier name has no XML tag
1059 name, i.e. this name is not visible in XML and is not translated.
1061 - A leading underscore is removed, but the underscore indicates that: **a**) a
1062 struct/class member name or parameter name has a wildcard XML tag name (i.e.
1063 matches any XML tag), or **b**) a type name that has a
1064 [document root element definition](#toxsd9-7).
1066 - Trailing underscores are removed (i.e. trailing underscores can be used to
1067 avoid name clashes with keywords).
1069 - Underscores within names are translated to hyphens (hyphens are more common
1072 - `_USCORE` is translated to an underscore in the translated XML tag name.
1074 - `_DOT` is translated to a dot (<i>`.`</i>) in the translated XML tag name.
1076 - `_xHHHH` is translated to the Unicode character with code point HHHH (hex).
1078 - C++11 Unicode identifier name characters in UTF-8 are translated as-is.
1080 For example, the C/C++ namespace qualified identifier name `s_a__my_way` is
1081 translated to the XML tag name <i>`s-a:my-way`</i> by translating the prefix `s_a`
1082 and the local name `my_way`.
1084 Struct/class member and parameter name translation can be overruled by using
1085 [backtick XML tags](#toxsd9-5-1) (with gSOAP 2.8.30 and greater).
1087 🔝 [Back to table of contents](#)
1089 C++ bool and C alternative {#toxsd3}
1090 --------------------------
1092 The C++ `bool` type is bound to built-in XSD type <i>`xsd:boolean`</i>.
1094 The C alternative is to define an enumeration:
1097 enum xsd__boolean { false_, true_ };
1100 or by defining an enumeration in C with pseudo-scoped enumeration constants:
1103 enum xsd__boolean { xsd__boolean__false, xsd__boolean__true };
1106 The XML value space of these types is <i>`false`</i> and <i>`true`</i>, but also accepted
1107 are <i>`0`</i> and <i>`1`</i> values for <i>`false`</i> and <i>`true`</i>, respectively.
1109 To prevent name clashes, `false_` and `true_` have a trailing underscore in
1110 their `enum` symbols. Trailing underscores are removed from the XML value space.
1112 🔝 [Back to table of contents](#)
1114 Enumerations and bitmasks {#toxsd4}
1115 -------------------------
1117 Enumerations are mapped to XSD simpleType enumeration restrictions of
1118 <i>`xsd:string`</i>, <i>`xsd:QName`</i>, and <i>`xsd:long`</i>.
1120 Consider for example:
1123 enum ns__Color { RED, WHITE, BLUE };
1126 which maps to a simpleType restriction of <i>`xsd:string`</i> in the soapcpp2-generated
1131 <simpleType name="Color">
1132 <restriction base="xsd:string">
1133 <enumeration value="RED"/>
1134 <enumeration value="WHITE"/>
1135 <enumeration value="BLUE"/>
1141 Enumeration name constants can be pseudo-scoped to prevent name clashes,
1142 because enumeration name constants have a global scope in C and C++:
1145 enum ns__Color { ns__Color__RED, ns__Color__WHITE, ns__Color__BLUE };
1148 You can also use C++11 scoped enumerations to prevent name clashes:
1151 enum class ns__Color : int { RED, WHITE, BLUE };
1154 Here, the enumeration class base type `: int` is optional. In place of `int`
1155 in the example above, we can also use `int8_t`, `int16_t`, `int32_t`, or
1158 The XML value space of the enumertions defined above is <i>`RED`</i>, <i>`WHITE`</i>, and
1161 Prefix-qualified enumeration name constants are mapped to simpleType
1162 restrictions of <i>`xsd:QName`</i>, for example:
1165 enum ns__types { xsd__int, xsd__float };
1168 which maps to a simpleType restriction of <i>`xsd:QName`</i> in the soapcpp2-generated
1173 <simpleType name="types">
1174 <restriction base="xsd:QName">
1175 <enumeration value="xsd:int"/>
1176 <enumeration value="xsd:float"/>
1182 Enumeration name constants can be pseudo-numeric as follows:
1185 enum ns__Primes { _3 = 3, _5 = 5, _7 = 7, _11 = 11 };
1188 which maps to a simpleType restriction of <i>`xsd:long`</i>:
1192 <simpleType name="Color">
1193 <restriction base="xsd:long">
1194 <enumeration value="3"/>
1195 <enumeration value="5"/>
1196 <enumeration value="7"/>
1197 <enumeration value="11"/>
1203 The XML value space of this type is <i>`3`</i>, <i>`5`</i>, <i>`7`</i>, and <i>`11`</i>.
1205 Besides (pseudo-) scoped enumerations, another way to prevent name clashes
1206 accross enumerations is to start an enumeration name constant with one
1207 underscore or followed it by any number of underscores, which makes it
1208 unique. The leading and trailing underscores are removed from the XML value
1212 enum ns__ABC { A, B, C };
1213 enum ns__BA { B, A }; // BAD: B = 1 but B is already defined as 2
1214 enum ns__BA_ { B_, A_ }; // OK
1217 The gSOAP soapcpp2 tool permits reusing enumeration name constants across
1218 (non-scoped) enumerations as long as these values are assigned the same
1219 constant. Therefore, the following is permitted:
1222 enum ns__Primes { _3 = 3, _5 = 5, _7 = 7, _11 = 11 };
1223 enum ns__Throws { _1 = 1, _2 = 2, _3 = 3, _4 = 4, _5 = 5, _6 = 6 };
1226 A bitmask type is an `enum*` "product enumeration" with a geometric,
1227 power-of-two sequence of values assigned to the enumeration constants:
1230 enum* ns__Options { SSL3, TLS10, TLS11, TLS12, TLS13 };
1233 where the product enum assigns 1 to `SSL3`, 2 to `TLS10`, 4 to `TLS11`, 8
1234 to `TLS12`, and 16 to `TLS13`, which allows these enumeration constants to be
1235 used in composing bitmasks with `|` (bitwise or) `&` (bitwise and), and `~`
1239 enum ns__Options options = (enum ns__Options)(SSL3 | TLS10 | TLS11 | TLS12 | TLS13);
1240 if (options & SSL3) // if SSL3 is an option, warn and remove from options
1247 The bitmask type maps to a simpleType list restriction of <i>`xsd:string`</i> in the
1248 soapcpp2-generated XML schema:
1252 <simpleType name="Options">
1254 <restriction base="xsd:string">
1255 <enumeration value="SSL3"/>
1256 <enumeration value="TLS10"/>
1257 <enumeration value="TLS11"/>
1258 <enumeration value="TLS12"/>
1259 <enumeration value="TLS13"/>
1266 The XML value space of this type consists of all 16 possible subsets of the
1267 four values, represented by an XML string with space-separated values. For
1268 example, the bitmask `TLS10 | TLS11 | TLS12` equals 14 and is represented by
1269 the XML text <i>`TLS10 TLS11 TLS12`</i>.
1271 You can also use C++11 scoped enumerations with bitmasks using `enum*` product
1275 enum* class ns__Options { SSL3, TLS10, TLS11, TLS12, TLS13 };
1278 The base type of a scoped enumeration bitmask, when explicitly given, is
1279 ignored. The base type is either `int` or `int64_t`, depending on the number
1280 of constants enumerated in the bitmask.
1282 To convert `enum` name constants and bitmasks to a string, we use the
1283 auto-generated function for enum `T`:
1286 const char *soap_T2s(struct soap*, enum T val)
1289 The string returned is stored in an internal buffer of the current `soap`
1290 context, so you should copy it to keep it from being overwritten. For example,
1291 use `char *soap_strdup(struct soap*, const char*)`.
1293 To convert a string to an `enum` constant or bitmask, we use the auto-generated
1297 int soap_s2T(struct soap*, const char *str, enum T *val)
1300 This function takes the name (or names, space-separated for bitmasks) of
1301 the enumeration constant in a string `str`. Names should be given without the
1302 pseudo-scope prefix and without trailing underscores. The function sets `val`
1303 to the corresponding integer enum constant or to a bitmask. The function
1304 returns `SOAP_OK` (zero) on success or an error if the string is not a valid
1307 🔝 [Back to table of contents](#)
1309 Numerical types {#toxsd5}
1312 Integer and floating point types are mapped to the equivalent built-in XSD
1313 types with the same sign and bit width.
1315 The `size_t` type is transient (not serializable) because its width is platform
1316 dependent. We recommend to use `uint64_t` instead.
1318 The XML value space of integer types are their decimal representations without
1321 The XML value space of floating point types are their decimal representations.
1322 The decimal representations are formatted with the printf format string `"%.9G"`
1323 for floats and the printf format string `"%.17lG"` for double. To change the
1324 format strings, we can assign new strings to the following `soap` context
1328 soap.float_format = "%g";
1329 soap.double_format = "%lg";
1330 soap.long_double_format = "%Lg";
1333 Decimal representations may result in a loss of precision of the least
1334 significant decimal. Therefore, the format strings that are used by default
1335 are sufficiently precise to avoid loss, but this may result in long decimal
1336 fractions in the XML value space.
1338 The `long double` extended floating point type requires a custom serializer:
1341 #import "custom/long_double.h"
1342 ... // use long double
1345 You can now use `long double`, which has a serializer that serializes this type
1346 as <i>`xsd:decimal`</i>. Compile and link your code with the file
1347 <i>`gsoap/custom/long_double.c`</i>.
1349 The value space of floating point values includes the special values
1350 <i>`INF`</i>, <i>`-INF`</i>, and <i>`NaN`</i>. You can check a value for plus
1351 or minus infinity and not-a-number as follows:
1354 soap_isinf(x) && x > 0 // is x INF?
1355 soap_isinf(x) && x < 0 // is x -INF?
1356 soap_isnan(x) // is x NaN?
1359 To assign these values, use:
1362 // x is float // x is double, long double, or __float128
1363 x = FLT_PINFY; x = DBL_PINFTY;
1364 x = FLT_NINFY; x = DBL_NINFTY;
1365 x = FLT_NAN; x = DBL_NAN;
1368 If your system supports `__float128` then you can also use this 128 bit
1369 floating point type with a custom serializer:
1372 #import "custom/float128.h"
1373 ... // use xsd__decimal
1376 Then use the `xsd__decimal` alias of `__float128`, which has a serializer. Do
1377 not use `__float128` directly, which is transient (not serializable).
1379 To check for <i>`INF`</i>, <i>`-INF`</i>, and <i>`NaN`</i> of a `__float128`
1383 isinfq(x) && x > 0 // is x INF?
1384 isinfq(x) && x < 0 // is x -INF?
1385 isnanq(x) // is x NaN?
1388 The range of a `typedef`-defined numerical type can be restricted using the range
1389 `:` operator with inclusive lower and upper bounds. For example:
1392 typedef int ns__narrow -10 : 10;
1395 This maps to a simpleType restriction of <i>`xsd:int`</i> in the soapcpp2-generated
1400 <simpleType name="narrow">
1401 <restriction base="xsd:int">
1402 <minInclusive value="-10"/>
1403 <maxInclusive value="10"/>
1409 The lower and upper bound of a range are optional. When omitted, values are
1410 not bound from below or from above, respectively.
1412 The range of a floating point `typedef`-defined type can be restricted within
1413 floating point constant bounds.
1415 Also with a floating point `typedef` a `printf`-format pattern can be given of the
1416 form `"%[width][.precision]f"` to format decimal values using the given width
1417 and precision fields:
1420 typedef float ns__PH "%5.2f" 0.0 : 14.0;
1423 This maps to a simpleType restriction of <i>`xsd:float`</i> in the soapcpp2-generated
1428 <simpleType name="PH">
1429 <restriction base="xsd:float">
1430 <totalDigits value="5"/>
1431 <fractionDigits value="2"/>
1432 <minInclusive value="0"/>
1433 <maxInclusive value="14"/>
1439 For exclusive bounds, we use the `<` operator instead of the `:` range
1443 typedef float ns__epsilon 0.0 < 1.0;
1446 Values `eps` of `ns__epsilon` are restricted between `0.0 < eps < 1.0`.
1448 This maps to a simpleType restriction of <i>`xsd:float`</i> in the soapcpp2-generated