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

_______________________________________________


_______________________________________________

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 {
string name;
string address;
int telno;
}

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();
String xml = xstrm.toXML(user);

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.



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.

_______________________________________

Recommended XML Books

cover
cover
cover
cover
cover
cover






 

 

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!


New XML Books Titles - Best Seller's @ Amazon.com

Visit XML Training Material Guide Homepage

Technology helps engage students - how do classroom instruction and social dynamics change when the classroom is completely dependant on modern technology?

Dallas Web Design- local Dallas web design firm offers site design and backend system development