5

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? Commented Mar 15, 2010 at 13:09
  • 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? Commented Mar 15, 2010 at 13:11
  • 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. Commented Mar 15, 2010 at 13:25

3 Answers 3

6

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

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks @Pablo. I could use a program from the "certain tools" list to get the schema from the xml file. Now is easy to convert it to java classes using JAXB.
2

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

2 Comments

The problem is generating the java class from an example xml file. XStream is great at taking existing classes and converting to/from XML, not so good when you only have the xml.
This link to XStream no longer works - it goes to a server which requires authentication. Is part of the path missing?
-1

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.