Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

java

jaxb

xjc

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?

like image 299
Daniel Esponda Avatar asked Aug 23 '13 20:08

Daniel Esponda


People also ask

How do I use JAXB XJC?

Open a command prompt. Run the JAXB schema compiler, xjc command from the directory where the schema file is located. The xjc schema compiler tool is located in the app_server_root \bin\ directory. Use the generated JAXB objects within a Java application to manipulate XML content through the generated JAXB classes.

What is JAXB XJC?

Use the Java™ Architecture for XML Binding (JAXB) tools to generate Java classes from an XML schema with the xjc schema compiler tool. JAXB is an XML-to-Java binding technology that enables transformation between schema and Java objects and between XML instance documents and Java object instances.

How does JAXB marshalling work?

In JAXB, marshalling involves parsing an XML content object tree and writing out an XML document that is an accurate representation of the original XML document, and is valid with respect the source schema. JAXB can marshal XML data to XML documents, SAX content handlers, and DOM nodes.


2 Answers

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:

  • http://blog.bdoughan.com/2010/09/processing-atom-feeds-with-jaxb.html
like image 157
bdoughan Avatar answered Oct 23 '22 08:10

bdoughan


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

like image 38
xQbert Avatar answered Oct 23 '22 09:10

xQbert