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..
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
+1 for Joachim's answer, and to add one of my favorite features, JAXB 2.0 creates Java enums from restricted simple types.
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.
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.