Generate Java class from XML file, using XStream

坚强是说给别人听的谎言 提交于 2019-12-18 19:41:54

问题


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?


回答1:


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

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




回答2:


I think it's not possible using XStream but I've already done it using JAXB.

Basically, the steps are generating a xsd from the xml files and then generating the Java classes from the xsd.

Have a look at this tutorial:

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




回答3:


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

This for xml file.



来源:https://stackoverflow.com/questions/12454240/generate-java-class-from-xml-file-using-xstream

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!