How about gSOAP? It is open source and freely available under the GPL license. Despite its name, the gSOAP toolkit is a generic XML data binding tool and allows you to bind your C and C++ data to XML automatically. There is no need to use an XML parser API, just let it read/write your data in XML format for you. If you really need a super-simple C++ XML parser then gSOAP may be an overkill. But for everything else it has worked well as testimonials show for many industrial applications since gSOAP was introduced in 2001.
Here is a brief list of features:
- Portable: Windows, Linux, Mac OS X, Unix, VxWorks, Symbian, Palm OS, WinCE, etc.
- Small footprint: 73KB code and less than 2K data to implement an XML web service client app (no DOM to limit memory usage).
- Fast: do not believe what other tools claim, the true speed should be measured with I/O. For gSOAP it is over 3000 roundtrip XML messages over TCP/IP. XML parsing overhead is negligible as it is a simple linear scan of the input/output while (de)serialization takes place.
- XML support: XML schema (XSD) import/export, WSDL import/export, XML namespaces, XML canonicalization, XML with attachments (MIME), optional use of DOM, many options to produce XML with indentation, use UTF8 strings, etc.
- XML validation: partial and full (option)
- WS support: WS-Security, WS-ReliableMessaging, WS-Addressing, WS-Policy, WS-SecurityPolicy, and other.
- Debugging: integrated memory management with leak detection, logging.
- API: no API to learn, only "soap" engine context initialization, then use the read/write interface for your data, and "soap" engine context destruction.
For example:
class Address
{
std::string name;
std::vector<LONG64> number;
time_t date;
};
Then run "soapcpp2" on the Address
class declaration above to generate the soap_read_Address
and soap_write_Address
XML reader and writer, for example:
Address *a = new Address();
a = ...;
soap ctx = soap_new();
soap_write_Address(ctx, a);
soap_end(ctx);
soap_free(ctx);`
This produces an XML representation of the Address a
object. By annotating the header file declarations with XML namespace details (not shown here), the tools also generate schemas. This is a simple example. The gSOAP tools can handle a very broad range of C and C++ data types, including pointer-based linked structures and even (cyclic) graphs (rather than just trees).
Hope this helps.