By Markus Sprunck; Revision: 1.2; Status: final; Last Content Change: Feb 4, 2013;
To create XML from Java objects is something that can be very error prone, e.g. doing the correct encoding of the various data types can be tricky. This is the reason why you never should do this by your own in Java. One of my favorite library to convert objects from and to XML is XStream. The following code sample describes some basic features.
It creates an instance of a class, serializes the object to XML and back again to a new object. To run the sample you need three libraries in the build path (i) xstream-1.4.2.jar, (ii) xmlpull-18.104.22.168.jar and (iii) xpp3_min-1.1.4c.jar.