views:

217

answers:

4

I need to write a linux c++ app which saves it settings in XML format (for easy hand editing) and also communicates with existing apps through XML messages over sockets and HTTP. Problem is that I haven't been able to find any intelligent libs to help me, I don't particular feel like writing DOM or SAX code just to write and read some very simple messages.

Boost Serialization was almost a match, but it adds a lot of boost-specific data to the xml it generates. This obviously doesn't work well for interchange formats. I'm wondering if it is possible to make Boost Serialization or some other c++ serialization library generate clean xml. I don't mind if there are some required extra attributes - like a version attribute, but I'd really like to be able to control their naming and also get rid of 'features' that I don't use - tracking_level and class_id for instance.

Ideally I would just like to have something similar to xstream in Java. I am aware of the fact that c++ lacks introspection and that it is therefore necessary to do some manual coding - but it would be nice if there was a clean solution to just read and write simple XML without kludges!

If this cannot be done I am also interested in tools where the XML schema is the canonical resource (contract first) - a good JAXB alternative to C++. So far I have only found commercial solutions like CodeSynthesis XSD. I would prefer open source solutions. I have tried gSoap - but it generates really ugly code and it is also SOAP-specific.

In desperation I also started looking at alternative serialization formats for protobuffers. This exists - but only for Java! It really surprises me that protocol buffers seems to be a better supported data interchange format than XML.

I'm going mad just finding libs for this app and I really need some new ideas. Anyone?

A: 

I'm not sure exactly what it provides and therefore if it's what you are looking for but Qt has an xml module. It also has a network module which sounds as if it may be of some use to you.

Troubadour
A: 

Just to clarify, CodeSynthesis XSD[1] is an open-source project. It is dual-licensed under copy left (GPLv2) and proprietary licenses, just like many other projects including MySQL, Berkeley DB, Qt, etc. Perhaps what you are looking for is a non-copy-left open source solution that you can use in your project without having to share the code with others. And, BTW, gSOAP is also GPL'ed, at least the XML Schema to C++ part of it.

[1] http://www.codesynthesis.com/products/xsd/

Boris

Boris Kolpackov
Thanks, I dind't actually notice that CodeSynthesis was GPL:ed, since I read about it on a site which had 'licence cost' listed in a table, so I just assumed that it was commercial only.
disown
Hm, do you by any chance remember which website it was that listed the licensing cost information?
Boris Kolpackov
A: 

To further expand on Troubadour's answer, I've used Qt's XML libraries with great success doing something very close to what you are. In my own case, I serialize config data to a local file and then occasionally stream it around to other threads.

QXmlStreamWriter and QXmlStreamReader are the two classes in question. Here is an example using them.

For my own XML serialization, I have complete control over the actual format produced and it only took a few hundred lines of code to achieve. The nicest thing I can say about using Qt's XML is that I could focus on the content and let the libraries do the painful work of marking up the data - which is ideal.

Finally, here is some info on Qt Licenses (Commercial, GPL, LGPL).

reshen