Using XStream for java XML serialization

With 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.



_______________________________________________

FREE Subscription

Subscribe to our mailing list and receive new articles
through email. Keep yourself updated with latest
developments in the industry.

Name:
Email:

Note : We never rent, trade, or sell my email lists to
anyone. We assure that your privacy is respected
and protected.

_______________________________________







 

 

FREE Subscription

Stay Current With the Latest Technology Developments Realted to XML. Signup for Our Newsletter and Receive New Articles Through Email.

Name:

Email:

Note : We never rent, trade, or sell our email lists to anyone. We assure that your privacy is respected and protected.

 

 

Add to My Yahoo!

Visit XML Training Material Guide Homepage

 

 

Copyright - © 2004 - 2017 - All Rights Reserved.