Editable XML Serialization

Dear list members, I guess it's one of the hardest search terms around but I would like to know if there is any editable XML serialization provided by Boost or other C++ libraries. And I don't mean the kind of thing that requires you to go jumping around through trees, with iterators etc. I don't want to see any iterator! I really iike the XML serialization method that boost::serialization provides: //! Give boost serialization libraries access to private fields friend class boost::serialization::access; //! Tell which private fields to serialize template<class Archive> void serialize(Archive & ar, const unsigned int version) { ar & boost::serialization::make_nvp("Phase", phase); ar & boost::serialization::make_nvp("Period", period); ar & boost::serialization::make_nvp("DutyCycle", dutycycle); } Just adding this to a file, and then: xml_out << boost::serialization::make_nvp("ApplicationConfig", config); Or: xml_in >> boost::serialization::make_nvp("ApplicationConfig", config); It's awesome! I don't need to care about descending trees, etc. However, the default serialization class does not allow for different orders of the XML tags, etc. It doesn't use the "ApplicationConfig" string, but just assumes that XML tag should be there if this read operation. If you change anything in the XML file, it is likely you will get a segfault, and you won't know what is causing the problem exactly. It would be so great if there is something like this in which the XML files can actually be edited! I am almost sure that there should be something like that, but I can't find it. Thanks in advance, Anne

Hi,
Dear list members,
I guess it's one of the hardest search terms around but I would like to know if there is any editable XML serialization provided by Boost or other C++ libraries. And I don't mean the kind of thing that requires you to go jumping around through trees, with iterators etc. I don't want to see any iterator!
lit("</data1>") >> lit("<data2>") >> int_ >> lit("</data2>") >>
I thought of something like this too. Actually, a specific XML-Format
could easily be implemented using boost.spirit:
qi::rule
It would be so great if there is something like this in which the XML files can actually be edited! I am almost sure that there should be something like that, but I can't find it.
You can edit the file by using a karma-rule that works exactly like the qi::rule, but is used for output instead. Spirit is very fast, probably faster than editing the XML and saving it using another xml-library. Regards, michi7x7

Anne van Rossum wrote:
Dear list members,
I guess it's one of the hardest search terms around but I would like to know if there is any editable XML serialization provided by Boost or other C++ libraries. And I don't mean the kind of thing that requires you to go jumping around through trees, with iterators etc. I don't want to see any iterator!
I really iike the XML serialization method that boost::serialization provides:
//! Give boost serialization libraries access to private fields friend class boost::serialization::access;
//! Tell which private fields to serialize template<class Archive> void serialize(Archive & ar, const unsigned int version) { ar & boost::serialization::make_nvp("Phase", phase); ar & boost::serialization::make_nvp("Period", period); ar & boost::serialization::make_nvp("DutyCycle", dutycycle); }
Just adding this to a file, and then:
xml_out << boost::serialization::make_nvp("ApplicationConfig", config);
Or: xml_in >> boost::serialization::make_nvp("ApplicationConfig", config);
It's awesome! I don't need to care about descending trees, etc. However, the default serialization class does not allow for different orders of the XML tags, etc. It doesn't use the "ApplicationConfig" string, but just assumes that XML tag should be there if this read operation. If you change anything in the XML file, it is likely you will get a segfault, and you won't know what is causing the problem exactly.
It would be so great if there is something like this in which the XML files can actually be edited! I am almost sure that there should be something like that, but I can't find it.
A rich subject which comes up from time to time. Here are a few
miscelleaneous observations.
a) Most of the time what people want when they ask this question is
xml_in >> my data structure for some arbitrarily defined structure. Of
course after you become familiar with the library, it's easy to see that
this is not possible. It's annoying to me how often this is stated as
a failing of the library.
b) It is possble to so some limited editing of xml (or other
archives) but this would be an ad hoc procedure subject to
errors. you might change a value here and there but the minute
you change something tracked or add a value to a collection
or whatever, you're not going to be able to keep things consistent.
I guess you're familiar with this.
I've thought about this alot. Here are some ideas that I thought
about.
a) create an xml_archive along with an xml schema which would
be friendly with known xml editors. I thought about this alot an
concluded that it would be too much like training an ant to train
a flea. I don't think it would be possible to make a bunch of
rules that an xml editor could follow and guarentee that that
the resulting C++ data object would be correct. Even it were
possible, one would likely have to add a bunch of "helper"
information to get it right. It would be hard to use, easy to misuse,
and a maintainence (and support) nightmare.
So what I want to do is to make the following:
edit_oarchive

Robert Ramey
Anne van Rossum wrote:
Dear list members,
I guess it's one of the hardest search terms around but I would like to know if there is any editable XML serialization provided by Boost or other C++ libraries. And I don't mean the kind of thing that requires you to go jumping around through trees, with iterators etc. I don't want to see any iterator!
I really iike the XML serialization method that boost::serialization provides:
A rich subject which comes up from time to time. Here are a few miscelleaneous observations.
a) Most of the time what people want when they ask this question is
xml_in >> my data structure for some arbitrarily defined structure. Of course after you become familiar with the library, it's easy to see that this is not possible. It's annoying to me how often this is stated as a failing of the library.
What I want "at the C++ side" so to say, is just the same as with boost::serialization. That supports already "custom" data structures, because in the serialize(Archive & ar,...) routine it is possible to define what fields to write/read. I am not talking about marshalling / unmarshalling to entire objects. Serializing arbitrary data structures does not make sense to me. However, I am not familiar with the library, so perhaps I misunderstood you. Forgive me, I just encountered it today.
b) It is possble to so some limited editing of xml (or other archives) but this would be an ad hoc procedure subject to errors. you might change a value here and there but the minute you change something tracked or add a value to a collection or whatever, you're not going to be able to keep things consistent. I guess you're familiar with this.
Yes.
I've thought about this alot. Here are some ideas that I thought about.
a) create an xml_archive along with an xml schema which would be friendly with known xml editors. I thought about this alot an concluded that it would be too much like training an ant to train a flea. I don't think it would be possible to make a bunch of rules that an xml editor could follow and guarentee that that the resulting C++ data object would be correct. Even it were possible, one would likely have to add a bunch of "helper" information to get it right. It would be hard to use, easy to misuse, and a maintainence (and support) nightmare.
So what I want to do is to make the following:
edit_oarchive
edit_iarchive The usage would be the following:
edit_archive
ea ... ea << my_data
That's a solution. I would then need to distribute a separate binary to manipulate the XML files. My idea was to "misuse" boost::serialization for writing XML configuration files without the need to manually build DOM-like structures. For just changing configuration parameters, a graphical solution might be a bit cumbersome. It's a nice idea nevertheless!
Robert Ramey
Anne

Anne van Rossum wrote:
Robert Ramey
writes:
xml_in >> my data structure for some arbitrarily defined structure. Of course after you become familiar with the library, it's easy to see that this is not possible. It's annoying to me how often this is stated as a failing of the library.
What I want "at the C++ side" so to say, is just the same as with boost::serialization. That supports already "custom" data structures, because in the serialize(Archive & ar,...) routine it is possible to define what fields to write/read. I am not talking about marshalling / unmarshalling to entire objects. Serializing arbitrary data structures does not make sense to me.
What I'm referring to is the the word xml_archive almost always conjures up in many persons imagination something which would take an arbitrary xml file and permit processng of it. Serialization can't do this even in concept since it maps the xml to the underly C++ data structures. This becomes obvious once you use it. But often people take it up thinking that it's something that it isn't.
However, I am not familiar with the library, so perhaps I misunderstood you. Forgive me, I just encountered it today.
lol - well it seems that you've actually used it - which makes you a lot more familiar to you than it is to a many of those who offer criticism.
b) It is possble to so some limited editing of xml (or other archives) but this would be an ad hoc procedure subject to errors. you might change a value here and there but the minute you change something tracked or add a value to a collection or whatever, you're not going to be able to keep things consistent. I guess you're familiar with this.
Yes.
...
The usage would be the following:
edit_archive
ea ... ea << my_data That's a solution. I would then need to distribute a separate binary to manipulate the XML files.
yes - but that binary would be generated "for free" without having to code anything.
My idea was to "misuse" boost::serialization for writing XML configuration files without the need to manually build DOM-like structures.
Indeed - any many have traveled this path. And, as I understand it some success in specific cases. This has been done by tweaking the xml_archive class or deriving from the current one. So for those cases it's an option. Of course, personally I'm more interested in a more general solution.
For just changing configuration parameters, a graphical solution might be a bit cumbersome. It's a nice idea nevertheless!
actually this would be a series of classes edit_archive<qtwidgets>, ... edit_archive<textwidgets> // no GUI necessary ! - just a text editor This last would likely be something generated with qi/karma which is a whole 'nother playpen. For simple configuratoin files, there are other options as well. boost property tree comes to mind. Also one might make archive which traps problematic cases like pointers so it would be usable to make only "simple editable" xml. etc, Robert Ramey

On 16 September 2010 01:56, Robert Ramey
Indeed - any many have traveled this path. And, as I understand it some success in specific cases. This has been done by tweaking the xml_archive class or deriving from the current one. So for those cases it's an option. Of course, personally I'm more interested in a more general solution.
Yes, of course, and it's already a nicer than most ways in which XML configuration is written or read, so I will definitely continue to use it. If you would be able to point me to some of those success cases, I would be obliged. Thanks for all the work, Robert! Anne
participants (3)
-
Anne van Rossum
-
michi7x7
-
Robert Ramey