How do I use JAXB/XJC to convert an XML file to an object?

Daniel Esponda picture Daniel Esponda · Aug 23, 2013 · Viewed 18k times · Source

I have been doing research on JAXB and XJC but from the documentation that is out there, including the Oracle pages and some of the Stack Overflow questions here, I don't think there is a clear definition of what is the difference between JAXB and XJC and how to use it to convert an XML file to an object.

So from my understanding JAXB is method for XML -> Java parsing and vice versa and xjc is one implementation for it that is included in the java tools?

Answer

bdoughan picture bdoughan · Aug 23, 2013

JAXB (JSR-222) implementations convert instances of Java classes (that may contain annotations) to/from XML. XJC (XML to Java Compiler) is a utility for generating those objects from an XML schema. It is included as part of the JDK since Java SE 6.

Exanple

Here is a link to my blog that demonstrates how to generate a Java model from an XML Schema: