views:

582

answers:

2

Hi,

does anyone know of a good library or method of converting the contents of a HashMap to XML and then parsing this to reconstruct the HashMap?

+8  A: 

The XStream library is what you want. http://xstream.codehaus.org/

It has a HashMap converter, and a tutorial on how to use convertors.

seanhodges
+1. XStream is the only thing that lets me stomach XML in Java.
Matt Ball
@seanhodges I didn't know this lib, does it have any advantages compared to jaxb?
stacker
@stacker I'm not too experienced with JAXB outside of Axis WS, but my understanding is that it generates Java code based on a schema. XStream lets you use objects based on your own Java classes. Not sure on other factors like performance or J2EE compliance though.
seanhodges
@stacker From the XStream FAQ: http://xstream.codehaus.org/faq.html#Other_Products_JAXB JAXB and XStream are two completely different approaches
matt b
+2  A: 

Java Architecture for XML Binding (JAXB) allows Java you to map Java classes to XML representations. JAXB provides two main features: the ability to marshal Java objects into XML and tunmarshal XML back into Java object

Where to start? Pick a tutorial from these:

In 15 minutes your done!

stacker
This requires you to define a XSD beforehand which might not fit in with what Aly is working with at all.
matt b