|
Boost : |
From: Robert Ramey (ramey_at_[hidden])
Date: 2004-06-04 11:19:46
Russell Balest wrote
> My request is support for xml <!-- comments --> in the serialization
> xml archive. I believe it currently chokes if I add a comment in an xml
> archive.
> The application is for QA to compose test objects in xml and then
> read them into applications with boost serialization.
> It would be nice to annotate the test object 'templates' with comments
> so QA can know what values are valid.
> Does someone know where in the code I can implement this easily.
> I just want to ignore the comments.
Hmmm - my question is: What program is generating the XML archive in the
first place? It its being generated by something other than the
serialization library itself, its not going to be easy to generate such an
archive that is guaranteed to be compatible with the C++ data structures of
the reading program. (The organization of the data in the C++ program is
what dicates the XML schema). At best it would be a maintenance pain in the
neck to keep the reading program based on serialization in sync with some
other program that doesn't use serialization to generate the XML archive.
On the other hand, if the original XML archive is generated by the
serialization library and just modified with comments, your request is very
easy to accommodate. Just create a use the following in your serialize
functions:
Template<class Archive>
Void serialize(Archive, my_class & t){
std::string comment;
ar & BOOST_NVP("comment", comment);
ar & BOOST_NVP("myclass_data", t);;
}
In which case your XML output will look like:
...
<comment></comment>
<myclass_data>..contents of t</myclass_data>
...
After the archive is created you can edit the space between
<comment> and </comment> with anything you want - it would be just thrown
away. Generally I wouldn't encourage the practice of editing an archive but
in this circumstance I could see it as an acceptable practice.
But then this raises the question if the comments are so important, why are
they being thrown them away? Shouldn't they be data read by the program?
Robert Ramey
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk