IntelliJ IDEA 2016.2 Help

Generating Java Code from XML Schema

On this page:

Introduction

This topic describes how to get a Java representation of an XML Schema, which involves mapping the elements of the XML Schema to members of a Java class. With IntelliJ IDEA, this transformation can be done using one of the following data binders:

  • JAXB generates classes and groups them in Java packages. A package consists of a Java class name and an ObjectFactory class. The latter is a factory that is used to return instances of a bound Java class.
  • XmlBeans converts an XML Schema into a Java class, compiles it, and places in the specified output .jar file.

Using JAXB

To generate a Java class from an XML Schema using JAXB

  1. In the active editor tab, open the desired Schema (.xsd) file or an XML document which contains the desired Schema. Then choose Tools | JAXB | Generate Java Code From XML Schema Using JAXB on the main menu.
  2. In the Generate Java from Xml Schema using JAXB dialog box that opens configure the generation procedure:
    • In the Schema/DTD/WSDL Path drop-down list, specify the file to be used as the basis for code generation. By default, the field shows the full path to the current file. Accept this suggestion or click the Browse button browseButton and select the desired file in the Select XML Schema File for JAXB Generation that opens.
    • From the Output Path drop-down list, select the module source directory to place the generated Java class in.
    • In the Package Prefix drop-down list, specify the package to include the generated stubs in.
    • Using the check boxes, configure additional options, such as generating annotation, setting the read-only status, downloading and installing additional libraries.

Using XmlBeans

To generate and compile a Java class from an XML Schema using XmlBeans

  1. In the active editor tab, open the desired Schema (.xsd) file or an XML document which contains the desired Schema. Then choose Tools | XmlBeans | Generate Java Code From XML Schema Using XmlBeans on the main menu.
  2. In the Generate Java Code From XML Schema using XmlBeans dialog box that opens configure the generation procedure:
    • In the Schema Path drop-down list, specify the file to be used as the basis for code generation. By default, the field shows the full path to the current file. Accept this suggestion or click the Browse button browseButton and select the desired file in the Select XML Schema /WSDL File for Generation dialog box that opens.
    • In the Output Path drop-down list, specify the name of the .jar file to place the generated and compiled Java code in. By default, IntelliJ IDEA suggests to create a new file types.jar. To overwrite an existing file, click the Browse button browseButton and choose the desired file in the Select XML Schema / Wsdl File for generation dialog box that opens.
    • To have missing libraries downloaded and installed automatically, select the Add necessary libraries in order for generated code compile and work check box.

See Also

Last modified: 23 November 2016