Serialize a Java object to XMLTo serialize Java objects to XML easily you can use the open source Java library XStream. This Java library is available for download at http://xstream.codehaus.org/download.html 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. import com.thoughtworks.xstream.XStream; Consider that you have a class as given below, class user { By creating an XStream object first, and then using the toXML() method of that object you can serialize the 'user' class as given below. XStream 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.
|
|
|||
|
||||
“Amazon and the Amazon logo are trademarks of Amazon.com, Inc. or its affiliates.”
Copyright - © 2004 - 2019 - All Rights Reserved.