Skip to main content

Can we map XML Schema with JAXB2?

1 reply [Last post]
Joined: 2004-11-24

It looks the JAXB2 using XSOM to mapping the xml schema. So is it possible to mapping XML schema to JAXB2 POJO?

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Joined: 2003-06-09

Yes, you can.

The problem is that the generated POJOs aren't very usable. For example, every reference is just a QName, so it's still up to application code to resolve them. Or, the notion of schema components aren't obvious in the schema4schema, so again it's up to application code to figure those things out.

For these reasosn, XSOM gives you better OM than XJC does (which isn't too surprising --- if a compiler can produce a better code than a human does, then there'd be no jobs left for us humans!) The downside of course is that it takes more time to write code manually.

Rewriting XSOM to use JAXB behind the scene to parse XML would be an interesting exercise. It should be possible, and if someone is interested in doing so, s/he is more than welcome!