从XML文件生成Java类,使用XStream [英] Generate Java class from XML file, using XStream

查看:415
本文介绍了从XML文件生成Java类,使用XStream的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有很多xml文件,我想使用XStream来管理它们。是否可以使用XStream生成对应于我的xml文件的java类?

I have many xml files and I would like to use XStream to manage them. Is it possible to generate java classes corresponding to my xml files using XStream?

推荐答案

XStream 软件来序列化和反序列化来自XML的Java对象。 XStream使用Reflection。

XStream is a software to serialize and deserialize a Java Object to and from XML. XStream uses Reflection for this. The class of the objects involved has to exist beforehand.

JAXB 是一个绑定框架,它也进行序列化和反序列化。 JAXB有注释来做这项工作。捆绑的框架来自一个xsd(< - 声明,描述一个特定的xml文档如何结构)生成类(完成与已经提到的注释)。

JAXB is a binding framework, which too does serialization and deserialization. JAXB has annotations to do this work. Bundled with the framework come tools to generate classes (complete with the already mentioned annotations) from an xsd (<-- declaration that describes how a specific xml document is structured).

所以你可以选择最适合你的需求。自己定义类,使用XStream或使用JAXB(或其他绑定框架...)和捆绑工具来生成类。每个变体都有优缺点... XStream更灵活,但JAXB更严格。 JAXB带来了额外的工具,XStream更像是一个工具本身...

So you can choose what fits your needs best. Defining classes on your own and use XStream or use JAXB (or other binding frameworks...) and the bundled tools to generate classes. Each variant has advantages and disadvantages... XStream is more flexible but JAXB more strict. JAXB brings additional tools, XStream is more like a tool itself...

这篇关于从XML文件生成Java类,使用XStream的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆