marshal Map<String, String> to .xml

Posted by richardl on Stack Overflow See other posts from Stack Overflow or by richardl
Published on 2010-05-28T21:42:28Z Indexed on 2010/05/28 22:12 UTC
Read the original article Hit count: 177

Filed under:
|
|

If I have Map setup like:

map.put("foo", "123");
map.put("bar", "456");
map.put("baz", "789");

then I want to do something like:

  for (String key : map.keySet().toArray(new String[0])) {
    // marshall out to .xml a tag with the name key and the
    // value map.get(key)
  }

So what it will marshal out is something like:

<map>
  <foo>123</foo>
  <bar>456</bar>
  <baz>789</baz>
</map>

Can I do this with some fancy JAXB annotations or is there something else that lends it self to dynamic element names?

TIA

© Stack Overflow or respective owner

Related posts about java

Related posts about Xml