views:

826

answers:

4

I am using C++ from Mingw, which is the windows version of GNC C++.

What I want to do is: serialize C++ object into an XML file and deserialize object from XML file on the fly. I check TinyXML. It's pretty useful, and (please correct me if I misunderstand it) it basically add all the nodes during processing, and finally put them into a file in one chunk using TixmlDocument::saveToFile(filename) function.

I am working on real-time processing, and how can I write to a file on the fly and append the following result to the file?

Thanks.

+2  A: 

I notice that each TiXmlBase Class has a Print method and also supports streaming to strings and streams.

You could walk the new parts of the document in sequence and output those parts as they are added, maybe?

Give it a try.....

Tony

Tony Lambert
Print() works very well, thanks Tony!
Lily
+2  A: 

BOOST has a very nice Serialization/Deserialization lib BOOST.Serialization.
If you stream your objects to a boost xml archive it will stream them in xml format. If xml is to big or to slow you only need to change the archive in a text or binary archive to change the streaming format.

TimW
A: 

Here's one example of C++ object serialization:
http://www.codeproject.com/KB/cpp/xmlserialization.aspx

swatkat
A: 

Here is a better example of C++ object serialization:

http://www.codeproject.com/KB/XML/XMLFoundation.aspx