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

18,558

Solution 1

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:

Solution 2

Not sure this is what you're after but it seems close...

Use Java Architecture for XML Binding (JAXB) xjc tooling to compile an XML schema file into fully annotated Java classes.

https://www.ibm.com/support/knowledgecenter/SSEQTP_8.5.5/com.ibm.websphere.base.doc/ae/twbs_jaxbschema2java.html

Share:
18,558
Daniel Esponda
Author by

Daniel Esponda

Software Consultant - Specialized Generalist

Updated on June 26, 2022

Comments

  • Daniel Esponda
    Daniel Esponda almost 2 years

    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?

  • Daniel Esponda
    Daniel Esponda over 10 years
    That makes more sense now... thanks for the blog post as well, it was helpful!