将 Java HashMap<K,V> 转储到 XML 并返回
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2336979/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Dump a Java HashMap<K,V> to XML and back
提问by Aly
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?
有没有人知道将 HashMap 的内容转换为 XML 然后解析它以重建 HashMap 的好库或方法?
回答by seanhodges
The XStream library is what you want. http://x-stream.github.io/
XStream 库正是您想要的。http://x-stream.github.io/
It has a HashMap converter, and a tutorial on how to use convertors.
它有一个HashMap 转换器,以及一个关于如何使用转换器的教程。
回答by stacker
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
XML 绑定的 Java 架构 (JAXB) 允许 Java 将 Java 类映射到 XML 表示。JAXB 提供两个主要功能:将 Java 对象编组为 XML 和将 XML 编组回 Java 对象的能力
Where to start? Pick a tutorial from these:
从哪儿开始?从这些中选择一个教程:
http://en.wikipedia.org/wiki/Java_Architecture_for_XML_Binding
http://java.sun.com/developer/technicalArticles/WebServices/jaxb/
http://en.wikipedia.org/wiki/Java_Architecture_for_XML_Binding
http://java.sun.com/developer/technicalArticles/WebServices/jaxb/
In 15 minutes your done!
在 15 分钟内完成!

