4
votes

How can I get java classes from an xml file?

In this situation, I don't have an XML schema and this way I can't use JAXB, Castor or other xml binding API as far as I know.

3
Can you describe what you want this xml file to describe? You say you don't have a schema, but are you interested in generating classes from something approximating a schema? - matt b
If you "can't use" any of the binding APIs i don't see any other way than to parse the DOM tree and create objects yourself. But why can't you use JAXB which is included in the more recent JDKs? - Stroboskop
jaxb requires a schema, which he doesn't have. There's plenty of tools that tries to generate a schema out of example xml files though. - nos

3 Answers

6
votes

You can generate schema from XML file using certain tools. Then, use Apache XMLBEANS to create your classes.

2
votes

XStream is great for XML -> objects and vice versa. Fast, lightweight, and works well without any schema.

-1
votes

Altova is also the best to generate java Classes from XML/XSD