• Create an XML Schema of the XML Information that needs to be bound

    <xs:schema xmlns:xs="" 
      xmlns:tst="" elementFormDefault="qualified" 
      <xs:element name="test">
            <xs:element ref="tst:child" maxOccurs="unbounded" minOccurs="0"/>
      <xs:element name="child">
          <xs:attribute name="test" use="optional" default="false" type="xs:boolean"/>
  • If necessary; customise the binding behavior, either by annotating the XML Schema or by specifying this in an external file.

    <jxb:bindings version="1.0"
      <jxb:bindings schemaLocation="test.xsd" node="/xs:schema">
        <jxb:globalBindings bindingStyle="elementBinding" choiceContentProperty="false"/>
          <jxb:package name="org.test"/>
  • Create the Java Classes and Interfaces using the Binding Compiler (xjc).

    java -jar jaxb\lib\jaxb-xjc.jar -extension -b test.jxb -d src -p org.test test.xsd
  • Compile the Java Classes and Interfaces.

    javac -sourcepath src -d out *.java
  • Unmarshall a XML Document

    JAXBContext context = JAXBContext.newInstance( "test.jaxb");
    Unmarshaller unmarshaller = context.createUnmarshaller();
    Collection result = (Collection)unmarshaller.unmarshal( new File( "input.xml"));
  • Marshall Java Objects to XML

    Marshaller marshaller = context.createMarshaller();
    marshaller.marshal( result, new FileOutputStream( "output.xml"));