trees) the XML output conforms to SOAP encoding for object graphs based on id-ref, see Section 7.5
for details.
To read the XML representation from standard input into a book object, use:
soap *ctx = soap new1(SOAP XML STRICT); // new context with option
book bk;
if (soap read book(ctx, &bk) != SOAP OK) ... error ...
else
cout ¡¡ bk.isbn ¡¡ ”, ” ¡¡ bk.title ¡¡ ”, ” ¡¡ bk.publisher ¡¡ endl;
... further use of bk ...
soap destroy(ctx); // delete deserialized objects
soap end(ctx); // delete temporaries
soap free(ctx); // delete context
Automatic built-in XML validation (enabled with SOAP XML STRICT) ensures that data members
are present so we can safely print them in this example, thus ensuring consistency of data with the
XML schema. Set the ctx->is input stream to read from a file/string stream instead of stdin.
The soap destroy and soap end calls deallocate the deserialized content, so use with care. In general,
memory management is automatic in gSOAP to avoid leaks.
The above uses a very simple example schema. The gSOAP toolkit handles all XML schema con-
structs defined by the XML schema standard. The toolkit is also able to (de)serialize pointer-based
C/C++ data structures (including cyclic graphs), structs/classes, unions, enums, STL containers,
and even special data types such as struct tm. Therefore, the toolkit works in two directions: from
WSDL/schema to C/C++ and from C/C++ to WSDL/schema.
The toolkit also handles multiple schemas defined in multiple namespaces. Normally the namespace
prefixes of XML namespaces are added to the C/C++ type definitions to ensure type uniqueness.
For example, if we would combine two schemas in the same application where both schemas define
a book object, we need to resolve this conflict. In gSOAP this is done using namespace prefixes,
rather than C++ namespaces (research has pointed out that XML namespaces are not equivalent
to C++ namespaces). Thus, the book class might actually be bound to an XML namespace and
the class would be named ns book, where ns is bound to the corresponding namespace.
More information on XML databinding support for C and C++, see Section 7.5.
1.5 Feature Overview
The highlights of gSOAP are:
• Unique interoperability features: the tools generate type-safe SOAP marshalling routines to
(de)serialize native and user-defined C and C++ data structures.
• Support WSDL 1.1, SOAP 1.1, SOAP 1.2, SOAP RPC encoding style, and document/literal
style. gSOAP is one of the few SOAP toolkits that support the full range of SOAP 1.1 RPC
encoding features including sparse multi-dimensional arrays and polymorphic types. For
example, a service operation with a base class parameter may accept derived class instances
from a client. Derived class instances keep their identity through dynamic binding. The
16