supernova
supernova

Reputation: 3271

Generating java binding classes using XML file without XSD schema file? Using any Castor or JAXB framework

I have a requirement to create java model classes (binding classes) from XML files. Unfortunately I don't have XSD schema. There are many already existing XML's.

Strangely , Castor or JAXB both use XSD schema to generate binding model classes. What if you don't have a schema? Not all XML are created using Schema!

Upvotes: 2

Views: 3174

Answers (2)

bdoughan
bdoughan

Reputation: 149057

The reason that XML binding technologies do not generate Java classes from XML is that it is an extra level of complexity:

  • Is that single XML element really a single element or a collection of size 1?
  • The data in the sample XML looks like an int, but is String content allowed?

You have a couple of options. The first is you can use a tool to generate an XML schema from the XML and then generate the classes from that. Or you could annotate your existing classes to map them to XML:

Upvotes: 2

Sahil Muthoo
Sahil Muthoo

Reputation: 12506

You could use a schema inference tool like Trang. It can produce xsd from xml. You could then tweak the generated schema or just feed it straight to JAXB/Castor etc.

Upvotes: 3

Related Questions