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?
-
Do you mean that you want to generate the javabean source by xml files automatically? – wodong Sep 17 '12 at 08:22
-
This is a very good question. Have you found a solution yet? – Guido Oct 09 '14 at 16:42
-
Honestly.. No. I am using: http://pojo.sodhanalibrary.com and http://jsongen.byingtondesign.com/ – Ulisse Nov 01 '14 at 11:39
3 Answers
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...

- 1,763
- 2
- 24
- 47
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:

- 3,877
- 2
- 28
- 42
yes.I think its possible, java class for xml file using XStream.Refer this and here
This for xml file.

- 4,241
- 6
- 41
- 75
-
Ok, but, referring to the link "this" you provided: I would like to generate the class contained in "Listing 3", starting from file "employeedata.txt" of the example. I want to generate the Java class given the xml file. Thank you. – Ulisse Sep 17 '12 at 06:59
-
ya.Xstream applicable for both txt and xml file.refer this for xml file.http://www.xml.com/pub/a/2004/08/18/xstream.html. – Ami Sep 17 '12 at 07:21