http://www.ibm.com/developerworks/xml/library/x-xstream/
Library of serializing object to XML and deserializing object back from XML
1) Example of converting a list of object into a XML file:
public boolean XStream2XML(List importEntryList, String strOutXMLFilePath)
{
XStream xs = new XStream();
//by default, xstream will use class's full name
//you could use alias to avoid that
xs.alias("entryList", List.class);
xs.alias("importentry", ImportEntry.class);
xs.alias("attribute", Attribute.class);
try
{
FileOutputStream fs = new FileOutputStream(strOutXMLFilePath);
xs.toXML(importEntryList, fs);
//a simpler version
//String xml = xs.toXML(importEntryList);
fs.close();
}
catch (Exception e1)
{
//e1.printStackTrace();
return false;
}
return true;
}
2) Example of converting XML back to Java Object
String xml = "......"; Person newJoe = (Person)xstream.fromXML(xml);