Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dump a Java HashMap<K,V> to XML and back

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?

like image 646
Aly Avatar asked Feb 25 '10 19:02

Aly


2 Answers

The XStream library is what you want. http://x-stream.github.io/

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

like image 124
seanhodges Avatar answered Sep 30 '22 06:09

seanhodges


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:

  • http://en.wikipedia.org/wiki/Java_Architecture_for_XML_Binding

  • http://jaxb.java.net/

  • http://java.sun.com/developer/technicalArticles/WebServices/jaxb/

In 15 minutes your done!

like image 30
stacker Avatar answered Sep 30 '22 05:09

stacker