使用XStream从XML文件生成Java类

时间:2022-08-19 21:47:47

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?

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

3 个解决方案

#1


6  

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.

XStream是一种将Java对象序列化和反序列化为XML的软件。 XStream为此使用了Reflection。所涉及的对象类必须事先存在。

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).

JAXB是一个绑定框架,它也可以进行序列化和反序列化。 JAXB有注释来完成这项工作。与框架捆绑在一起的工具是从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. 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...

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

#2


3  

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/

#3


0  

yes.I think its possible, java class for xml file using XStream.Refer this and here

是的。我认为它可能是使用XStream的xml文件的java类。在这里和这里

This for xml file.

这适用于xml文件。

#1


6  

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.

XStream是一种将Java对象序列化和反序列化为XML的软件。 XStream为此使用了Reflection。所涉及的对象类必须事先存在。

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).

JAXB是一个绑定框架,它也可以进行序列化和反序列化。 JAXB有注释来完成这项工作。与框架捆绑在一起的工具是从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. 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...

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

#2


3  

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/

#3


0  

yes.I think its possible, java class for xml file using XStream.Refer this and here

是的。我认为它可能是使用XStream的xml文件的java类。在这里和这里

This for xml file.

这适用于xml文件。