Generating Java beans from an XML schema

To allow developers to quickly build an XML application, the XML schema editor supports the generation of beans from an XML schema. Using these beans, you can quickly create an instance document or load an instance document that conforms to the XML schema without coding directly to the DOM APIs.

The following instructions were written for the Resource perspective, but they will also work in many other perspectives.

To generate beans from an XML schema,...

  1. Create a project that is configured to work with Java source code. The beans you generate from your XML schema must be contained in a project that is configured to work with Java source code. Projects such as a Java, Web, or Fragment project are all configured to work with Java source code. You do not have to store the XML schema file in a project that is configured to work with Java source, however, we recommend it.

  2. In the Navigator view, right-click the XML schema file and click Generate > Java . The Generate Java wizard opens.

  3. There are three different generators you can use to generate your beans. As you select them in the Generator field, a detailed description of them appear in the Description field.

    • XSD Beans Generator - generated simple, lightweight Java beans

    • SDO Generator - generates more robust Java beans

    • DOM Based XSD Beans Generator (Deprecated) - generates simple Java beans that encapsulate DOM objects

  4. Select the Generator you want to use.

  5. In the Container field, specify your project. You can also specify a source folder in a project to contain your Java beans; that is, a folder that is on the Java source path. You can verify that a folder is on the Java source path by looking in the Source page of the Java Build Path for the project (Right-click the project and select Properties > Java Build Path > Source). Click Browse to select from a list of all valid projects and folders that exist in the workbench.

  6. Type the name of the package. The step is only necessary if you select the DOM Based XSD Beans Generator (Deprecated) option.

  7. Click Finish.

  8. The beans and classes appear in the Navigator view in the location you specified. Double-click them to edit them in the Java or Class editor.

For more information on the rules used to generate beans from an XML schema, refer to the related information below.

Data binding rules for Java beans from XML schema files
This section describes the rules that are used to generate beans from an XML schema.