Wednesday, November 12, 2008

XStream - Convert XMl to Java & Vice Versa

XStream is a simple library to serialize objects to XML and back again.
XStream xstream = new XStream();
Person joe = new Person("Joe", "Walnes");
String xml = xstream.toXML(joe)
The resulting XML looks like this:
<code>
<person>
<firstname>Joe</firstname>
<lastname>Walnes</lastname>
<phone>
<code>123</code>
<number>1234-456</number>
</phone>
<fax>
<code>123</code>
<number>9999-999</number>
</fax>
</person></code>
Deserializing an object back from XML
Person newJoe = (Person)xstream.fromXML(xml);
Reference :http://xstream.codehaus.org/

No comments:

 
Free Domain Names @ .co.nr!