Java Reference
In-Depth Information
How It Works
The JDK includes the <JDK_HOME>/bin/xjc utility. The xjc utility is a
command-line application that creates Java bindings from schema files. The source
schema files can be several types, including XML Schemas, RELAX NG, and others.
The xjc command has several options for performing its work. Some of the most
common options specify the source schema file, the package of the generated Java
binding files, and the output directory that will receive the Java binding files.
You can get detailed descriptions of all the command-line options by using the
tools' -help option:
xjc -help
A Java binding contains annotated fields that correspond to the fields defined in the
XML Schema file. These annotations mark the root element of the schema file and all
other subelements. This is useful during the next step of XML processing, which in-
volves either unmarshalling or marshalling these bindings.
20-6. Unmarshalling XML to a Java Ob-
ject
Problem
You want to unmarshall an XML file and create its corresponding Java object tree.
Solution
Unmarshalling is the process of converting a data format, in this case XML, into a
memory representation of the object so that can be used to perform a task. JAXB
provides an unmarshalling service that parses an XML file and generates the Java ob-
jects from the bindings you created in Recipe 20-4. The following code can read the
file patients.xml from the org.java8recipes.chapter20.recipe20-6
package to create a Patients root object and its list of Patient objects:
Search WWH ::




Custom Search