简体   繁体   English

使用XStream从XML文件生成Java类

[英]Generate Java class from XML file, using XStream

I have many xml files and I would like to use XStream to manage them. 我有很多xml文件,我想使用XStream来管理它们。 Is it possible to generate java classes corresponding to my xml files using XStream? 是否可以使用XStream生成与我的xml文件对应的java类?

XStream is a software to serialize and deserialize a Java Object to and from XML. XStream是一个用于将Java对象序列化和反序列化为XML的软件。 XStream uses Reflection for this. XStream为此使用了Reflection。 The class of the objects involved has to exist beforehand. 所涉及的对象类必须事先存在。

JAXB is a binding framework, which too does serialization and deserialization. JAXB是一个绑定框架,它也可以进行序列化和反序列化。 JAXB has annotations to do this work. JAXB有注释来完成这项工作。 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). 与框架捆绑在一起的工具是从xsd生成类(包括已经提到的注释)(< - 描述特定xml文档结构的声明)。

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. 自己定义类并使用XStream或使用JAXB(或其他绑定框架...)和捆绑工具来生成类。 Each variant has advantages and disadvantages... XStream is more flexible but JAXB more strict. 每个变体都有优点和缺点...... XStream更灵活,但JAXB更严格。 JAXB brings additional tools, XStream is more like a tool itself... JAXB带来了额外的工具,XStream更像是一个工具本身......

I think it's not possible using XStream but I've already done it using JAXB. 我认为使用XStream是不可能的,但我已经使用JAXB完成了它。

Basically, the steps are generating a xsd from the xml files and then generating the Java classes from the xsd. 基本上,这些步骤是从xml文件生成xsd ,然后从xsd生成Java类。

Have a look at this tutorial: 看看这个教程:

http://theopentutorials.com/examples/java/jaxb/generate-java-class-from-xml-schema-using-jaxb-xjc-command/ http://theopentutorials.com/examples/java/jaxb/generate-java-class-from-xml-schema-using-jaxb-xjc-command/

yes.I think its possible, java class for xml file using XStream.Refer this and here 是的,我想用XStream.Refer的可能,对XML文件的Java类, 这里

This for xml file . 这适用于xml 文件

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM