Generating Java Classes from XML Schema Documents
See Also
You can use the JAXB Wizard to generate Java classes from an XML schema file.
Once you have the classes, you can use them in a variety of scenarios
to traverse the elements and attributes of the XML schema file.
To generate Java classes from an XML schema document:
- Make sure that you have installed the full distribution of the IDE,
since the JAXB Wizard is only provided
with the full distribution.
- Create a
project type to store the code that you will generate from the XML file.
The JAXB Wizard can be used with the 'Java Application', 'Java Class Library',
'Web Application' and 'EJB Module' project types.
- In the Projects window or Files window, right-click the project node
and choose New > Other. In the New File wizard, choose JAXB Binding
from the XML category. Click Next.
In the wizard, fill in the fields as described below:
- Binding Name. Specifies the name of the new JAXB binding, which will be used to identify it.
- Project. Displays the name of the current project.
- Schema File. The file that you want to work with can either be available locally or on-line.
- Schema Type. The following types of XML document are supported:
- XML Schema
- Relax NG
- Relax NG Compact
- XML DTD
- WSDL
- Package Name. Specifies the package to which the Java objects will be generated.
- Compiler Options. Many compiler options are available, as described here in the Java EE 5 Tutorial. However, in relation to the JAXB Wizard, only the following are relevant and you can set them using checkboxes in the wizard:
- nv. Do not perform strict validation of the input schema(s). By default, strict validation of the source schema is performed before processing. Note that this does not mean the binding compiler will not perform any validation; it simply means that it will perform less-strict validation.
- readOnly. Force the compiler to mark the generated Java sources read-only. By default, the compiler does not write-protect the Java source files it generates.
- npa. Suppress the generation of package level annotations into **/package-info.java. Using this switch causes the generated code to internalize those annotations into the other generated classes.
- verbose. Produce maximum compiler output, such as progress information and warnings.
- quiet. Suppress compiler output, such as progress information and warnings.
- Use Extension. By default, the compiler strictly enforces
the rules outlined in the Compatibility chapter of the JAXB Specification.
In the default (strict) mode, you are also limited to using only the
binding customizations defined in the specification. By using this option,
you will be allowed to use the JAXB Vendor Extensions.
- Use Binding File. Lets you import and edit one or more JAXB binding customization files.
- Use Catalog File. Lets you import and edit OASIS catalog files.
- Click Finish.
- Open the Files window, and notice that the Java classes have been
generated in the build folder.
- See Also
- About Mapping XML to Java
- Marshalling and Unmarshalling Java to XML
Legal Notices