Using XStream for java XML serializationWith serialization you can convert the java objects in to XML format easily. For this purpose there is an open source library called XStream. With this library you serialize and deserialize the java objects. You have to include the following import statement once you have installed that library in your system and made the appropriate changes in the class path. import com.thoughtworks.xstream.XStream; To create an xstream object you can use statements like, XStream xs = new XStream(); Once you have created this xstream object then you can serialize any class to XML format using code like, String to_xml = xs.toXML(ur_class); where 'ur_class' is the class that you want to serialize. If you have set the values in your class member variables in your program then you can get an XML output with the element names as the member variable names and the values of the elements as that of the values set for the member variables. With this library in place you can also deserialize from the XML document in to Java objects.
|
|
|||
|
||||
“Amazon and the Amazon logo are trademarks of Amazon.com, Inc. or its affiliates.”
Copyright - © 2004 - 2019 - All Rights Reserved.