Re: How to to convert object to XML string and back again
On Dec 18, 10:16 am, ap...@student.open.ac.uk wrote:
As a thought experiment I am considering how I would recode a java
program I have been working on in C++. This is an interesting
experiment for me because the program is in an environment where a
number of enterprise technologies are being used so it is interesting
to see how java and C++ differ in their support for enterprise
technologies. I stress it is only a thought experiment. I will NOT do
the coding, in fact the project is trying to migrate away from C++,
that is why I have rewritten the servers in java. The experience is
making me think that enterprise programming is easier in java because
of all the packages that have been developed over the years, some std,
some non-std but widely used open source.
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. In C++ I expect that most solutions (except
those that use macros) will involve writing save and restore methods
for each private member that is to be serialized.
I have not done much XML work in C++ but when I have I remember it
being very painful. I have used Xerces and never again! Gnome's libxml
is much better IMO but I have not used it to converts objects to XML
strings and back again, only to traverse the DOM. libxml is not too
bad for that, but can it also be used for stringyfying objects? If not
then I wonder what people use.
I use serialization. It works.
As far as serializing strings, that's possible: It is not
inconceivable to make a serialization framework where the target of
serialization converts types and values to a string encode of those
types and values [int:9107], storing them in an associative polyarchy
(my terminology) in XML like format, but not using XML, as XML is
grossly overrated. [XML is one of those things that some engineers
find insanely appealing without really understanding what about it
exactly is so appealing, which leads to inflated expectations of what
it can do for them, which is most often much less than they think.]
In any case, Java programmers, and programmers in some other
"interpreted" languages, should know by now that it is farcical to
make comparisons between C++ and Java. C++ is a language whose target
code is interpreted by a CPU. Java is a language whose target code is
interpreted by target code that is interpreted by a CPU. The
intermediate layer, the JVM, or Java diaper as some of us like to call
it, creates an environment that would be strange to C++, but is a
necessity for Java, and this inseparability leads one to ask whether
Java is a language or a language+environment.
On the matter of XML, I have been admonishing other engineers for
years that there will never be a system that magically converts from
XML to C++, or vice-versa, because the very proposition is senseless.
Most of them don't listen....there are 1000's of programmers around
the world today banging their heads trying to find a "breakthrough"
method for doing this. They think there is something magical about
XML, not realizing that the magic comes from a special computer, the
one sitting at the top of their neck, and that the other computer, the
one with 500 million transistors, not being artificially-intelligent,
is horribly inept at magic, and only does things by-the-book, and will
never be able to have a conversation of any kind with anything,
especially strings on disks, without gross changes to the C++
compiler, ultimately under the control of a human who has deliberate
and specified intent.
I get asked about once every 3-4 months by a Java/C#/C++-Convert
programmer if I know of a good package to do XML to C++ conversion. I
respond by asking them an equally senseless, equally irritating
-Le Chaud Lapin-
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]