Re: How to to convert object to XML string and back again
jaibuduvin@gmail.com (Le Chaud Lapin) wrote (abridged):
On Dec 18, 10:16 am, ap...@student.open.ac.uk wrote:
The program converts objects to XML strings and back again using
the reflection-based package XStream. I am wondering how one can
do a similar job in C++. I realise there is no reflection but
I don't mind a bit of manual work.
I happen to have been doing this recently. With no built-in language
reflection we just wrote all the functions by hand.
Personally I am highly suspicious of automated methods because in my
experience there are too many special cases needing too much programmer
knowledge. For example, we wanted to minimise file size by not storing
members that had their default values. The default value might not be
zero, and in some cases might be quite complex. When loading, if the
attribute wasn't present in the file, we needed to construct that complex
default. Sometimes it would depend on values loaded earlier.
Another problem area is schema evolution. As the data structures change
we need code to convert old XML into the new format during loads.
Automation only gets you so far. At some point you need to understand
what the data means.
I have had bad experiences in the past with systems that appear easy in
the easy cases but which don't scale well to the hard cases, and
especially don't handle easy cases /evolving into/ hard ones.
-- Dave Harris, Nottingham, UK.
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]