将 Java 对象图另存为 XML 文件 [英] Saving Java Object Graphs as XML file
问题描述
可用于将任意 Java 对象图保存为 XML 文件的最简单易用的技术是什么(并且能够在以后重新水化对象)?
What's the simplest-to-use techonlogy available to save an arbitrary Java object graph as an XML file (and to be able to rehydrate the objects later)?
推荐答案
这里最简单的方法是序列化对象图.Java 1.4 内置了对 XML 序列化的支持.
The easiest way here is to serialize the object graph. Java 1.4 has built in support for serialization as XML.
我成功使用的解决方案是 XStream (http://x-stream.github.io/)- 这是一个小型库,可让您轻松地对 XML 进行序列化和反序列化.
A solution I have used successfully is XStream (http://x-stream.github.io/)- it's a small library that will easily allow you to serialize and deserialize to and from XML.
缺点是您只能非常有限地定义结果 XML;在您的情况下,这可能不是必需的.
The downside is you can only very limited define the resulting XML; which might not be neccessary in your case.
这篇关于将 Java 对象图另存为 XML 文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!