Serialize a Java object to XML
To serialize Java objects to XML easily you can use the open source Java library XStream. This Java library is available for download at
Once you install this library you have to include the following import statement in your Java code to work with the classes and the methods available in that library.
Consider that you have a class as given below,
By creating an XStream object first, and then using the toXML() method of that object you can serialize the 'user' class as given below.
xstrm = new XStream();
You can use the print statements to print the output of the string xml. Similarly you can also deserialize the XML documents to Java objects. Lots of sample codes to do the conversion from Java objects to the XML and then to deserialize them to Java objects are available in many websites in the internet.
Copyright - © 2004 - 2017 - All Rights Reserved.