views:

2268

answers:

4

Want to use a library for XML schema to code generation and wanted to know if people have a preference between XMLBeans and JAXB. Performance, Schema validation capability, Memory Usage.. Any indicators will help..

+5  A: 

My personal preference would be JAXB. It has a more modern approach using annotations and many Java 5 features. XMLBeans on the other hand is still Java 1.4 compliant - if this is required for you. Some other thoughts in no particular oder are:

  • From Java 6 on JAXB is bundled with the JDK - so it is available out of the box.
  • JAXB works with annotated Java (POJO like) classes - XMLBeans generated interfaces and no classes
  • JAXB allows to annotate Java classes to use them for marshalling and unmarshalling or you can start with a XML Schema, generate the Java classes and then fo into un-/marshalling
  • XMLBeans allows only to start with a XML Schema, generates interfaces and then use this for un-/marshalling
Joachim
Also since JAXB is a specification you can pick between JAXB implementations (i.e. Metro, EclipseLink MOXy, etc...)
Blaise Doughan
+1  A: 

+1 for Joachim's answer, and to add one of my favorite features, JAXB 2.0 creates Java enums from restricted simple types.

Phil
+1  A: 

Another benefit to JAXB is that since you're working with POJOs, you can feel comfortable using them as first-class domain objects, and use them throughout your application stack.

Want to use them as your value objects for your DAO layer? How about as your model in the UI layer? Go for it.

That way, you have fewer mapping layers and DTOs, which means less code to write, test, and maintain.

matthewsteele
A: 

I prefer XMLBeans, because it comes with a handy tool called "inst2xsd" which allows you to generate a schema from an XML document. JAXB can only compile schemas, not generate them.

dogbane
JAXB 2 can generate XML Schemas, see http://download.oracle.com/docs/cd/E17409_01/javase/6/docs/api/javax/xml/bind/JAXBContext.html#generateSchema(javax.xml.bind.SchemaOutputResolver)
Blaise Doughan