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.



.

SetApp - 100 Apps for everything you ever wanted to do on Mac

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

 

 

“Amazon and the Amazon logo are trademarks of Amazon.com, Inc. or its affiliates.”

Copyright - © 2004 - 2019 - All Rights Reserved.