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 on开发者_JAVA技巧ly 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?
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.
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).
A quote from the question: "So far I have only found commercial solutions like CodeSynthesis XSD. I would prefer open source solutions"
CodeSynthesis XSD can be used by open source projects. The product has a Commercial Proprietary License but in addition to that it also have an Open source license (GPL version 2 but with additional freedom given). You are allowed to use it together with all "GPL-Compatible Free Software Licenses" and all "GPL-Incompatible Free Software Licenses" listed at http://www.gnu.org/licenses/license-list.html
The third license option for CodeSynthesis XSD is a Free Proprietary License for Small Vocabularies. You coud use that license for free if you are using a small XML schema.
Read more about the different CodeSynthesis XSD licenses here: http://www.codesynthesis.com/products/xsd/license.xhtml
In terms of functionality CodeSynthesis XSD also supports serializing and parsing of a generated binary format. You could use that format for efficient communication.
精彩评论