Workbook: NetBeans Enterprise Pack 5.5 XML Schema Tools Demo

Last Updated: 24 October 2006

This document is meant as a workbook that you can use to reproduce the actions demonstrated in the NetBeans Enterprise Pack 5.5 XML Schema Tools Demo.

Prerequisites

This workbook assumes that you have some knowledge of, and experience with XML (Extensible Markup Language).

System Requirements

This workbook assumes that your system meets the requirements specified in the System Requirements topic of the NetBeans Enterprise Pack 5.5 Release Notes.

Software Needed for the Workbook

Before you begin, you need to install the following software on your computer:

Contents

top


Creating the WebApplication Project

Typically, XML schema is used for defining the types used in a Web Service, so you will be using a web project to contain our documents.

Note: This step is not shown in the demo.

  1. In the IDE, choose File > New Project.
  2. In the Categories list, select the Web node.
  3. In the Projects list, select Web Application and click Next.
  4. In the Name and Location page, in the Project Name field, enter WebApplication and specify the project location.
  5. Accept all the other default values and settings and click Finish.
    The Projects window now contains a project node labeled WebApplication and the index.jsp file is open in the Source Editor.
  6. In the Source Editor, close index.jsp.

top


Adding the courier XML Schema File

You will start by creating an XML schema document that will define a package delivery service.

  1. Open the WebApplication project in the IDE.
  2. In the Projects window, expand the WebApplication project node.
  3. Select the Source Packages node, right-click and choose New > File/Folder.
    The New File wizard opens.
  4. In the Choose File Type page, in the Categories list, select the XML node, then in the File Types list, select XML Schema and click Next.
  5. In the Name and Location page of the wizard, in the File Name field, type courier.
  6. Accept the other default values and click Finish.
    The new file, courier.xsd, is opened in the Schema view of the XML schema editor.
  7. Maximize the Schema view by right-clicking the tab for the file and choosing Maximize Window from the pop-up menu.
    Maximizing the view lets you see more information about the schema.

top


Populating the courier XML Schema File

The Design view allows you to quickly populate a schema, without needing to know the complex details of how XML schema is defined.

  1. In the Schema view, click the Design button to switch to the Design view.
    Note: If you do not see the Palette window, from the IDE main menu, choose Window > Palette.
  2. Add a global complex type named CourierType by doing the following:
    1. In the XML Schema Components section of the Palette, click the Complex Type icon and drag it just below the Complex Types node in the schema design area.
    2. Type CourierType and press Enter.
  3. Add an element named name to the CourierType complex type by doing the following:
    1. In the XML Components section of the Palette, click the Element icon and drag it onto the CourierType complex type.
      Notice that the IDE automatically adds a Sequence component.
    2. Type name and press Enter.
  4. Add two more elements (startDate and vehicle) to the CourierType complex type by doing the following:
    1. In the XML Components section of the Palette, click the Element icon and drag it onto the courierType complex type.
    2. Type startDate and press Enter.
    3. In the XML Components section of the Palette, click the Element icon and drag it onto the courierType complex type.
    4. Type vehicle and press Enter.
  5. Add two attributes (first and last) to the name element by doing the following:
    1. In the XML Components section of the Palette, click the Attribute icon and drag it onto the name element.
    2. Type first and press Enter.
    3. In the XML Components section of the Palette, click the Attribute icon and drag it onto the name element.
    4. Type last and press Enter.

top


Changing the startDate Schema Component

You can search for XML schema components by name, attribute value, and even use regular expressions. The IDE highlights search results for easy navigation.

  1. In the Design view, click the Schema button to switch to the Schema view.
  2. In the Schema view, click the tree button Tree button in Schema view to switch to the tree mode of the view.
  3. Click the Find toolbar button.
    You can also choose Edit > Find from the IDE main menu or press Ctrl-F.
    The Find bar appears at the bottom of the Schema view.
  4. Click in the Find box, type startDate, and press Enter.
    The IDE selects the first matching occurrence (as it appears in the source).
  5. Close the Find bar by clicking the red "x" icon Close Find Bar in the Find bar.
  6. In the Schema view, right-click the startDate node and choose Customize from the pop-up menu.
    The Local Element Customizer dialog box opens.
  7. Under Type, select the Use Existing Type radio button and in the list, expand the Built-in Types node, select date, and click OK.

top


Adding the courier Schema Component in the Schema View

As with the Design view, you can easily create new schema components in the Schema view.

  1. In the tree mode of the Schema view, select the Elements node, right-click, and choose Add Element from the pop-up menu.
    The Element dialog box opens.
  2. In the Name field, type courier.
  3. Under Type, select the Use Existing Type radio button and in the list, expand the Complex Types node.
  4. Select CourierType and click OK.

top


Retrieving External Resources

It is often easier to reuse existing XML schema available on the Internet. In this example, you will retrieve the UBL Order schema, defined by the OASIS organization.

Note: If you want to step through this section offline, you should download Java WSDP.

  1. If the Output window is not visible, choose Window > Output.
    When the IDE retrieves the resources, informational messages appear in the Output window.
  2. In the Projects window, expand the WebApplication project node and expand the Source Packages node.
  3. Select the Source Packages node, right-click and choose New > File/Folder.
  4. In the New File dialog box, under Categories, select the XML node, and in the File Types list, select External XML Schema Document.
  5. Click Next.
    The New Retrieve Documents page opens.
  6. In the Specify Resource Location page, do the following:
    1. Select the From URL radio button.
    2. In the text field below the From URL radio button, type http://docs.oasis-open.org/ubl/cd-UBL-1.0/xsd/maindoc/UBL-Order-1.0.xsd
      In this example, you are retrieving the UBL sample schema, included with Java WSDP Version 2.0, directly from a URL.
    3. Accept the default value for the Save to Folder field and click Finish.
    Notice the information that appears in the Output window. The IDE shows which files are being copied to project folders and if there are any errors, they appear in the Output window.
  7. Close the Output window by clicking the close button in the window's title bar.

top


Referencing External Schemas

You will now add an import to reference the external schema files you just retrieved.

  1. In the Schema view of the courier.xsd file, select the Referenced Schemas node, right-click and choose Add > Import.
    The Import dialog box opens.
  2. In the Location list, expand the By Namespace node, then expand the urn:oasis:names:specification:ubl:schema:xsd:Order-1.0 node and select the UBL-Order-1.0.xsd node.
    The Namespace field below the Location list is filled in by the IDE, and contains the following value: urn:oasis:names:specification:ubl:schema:xsd:Order-1.0.
  3. In the New Prefix field, type order and click OK.
    The IDE adds the import to your schema file.

top


Adding the delivery Schema Component in the Schema View

You will now add another element that defines its own nested complex type.

  1. In the Schema view, select the Elements node, right-click, and choose Add Element from the pop-up menu.
    The Element dialog box opens.
  2. In the Name field, type delivery.
  3. Under Type, select the Inline Complex Type radio button and click OK.

top


Adding Element References

An element can be made up of references to other elements, even if they are defined in other schema documents.

  1. In the Schema view, select and right-click the delivery node and choose Add > Element Reference from the pop-up menu.
    The Element Reference dialog box opens.
  2. Expand the Referenced Schemas node > import node > Elements node.
  3. Select the Order node and click OK.
    The IDE has added the element reference. It has the following label: Order [1..1](->) node.
  4. In the Schema view, select and right-click the delivery node and choose Add > Element Reference from the pop-up menu.
    The Element Reference dialog box opens.
  5. Expand the Elements node.
  6. Select the courier (instance of CourierType) node and click OK.
    The new element reference is added to the schema. Its label is courier [1..1](->).

top


Finding Usages of a Schema Component

To see where a particular schema component is defined, you will use the Go To > Definition command. You will also use the Find Usages function to find all the usages of the Order schema component in the UBL-Order-1.0.xsd schema file.

  1. Select and right-click the Order [1..1](->) node and choose Go To > Definition.
    The IDE opens UBL-Order-1.0.xsd in the XML schema editor and highlights the Order element in that schema file.
  2. Right-click the Order node in the Schema view of the UBL-Order-1.0.xsd file and choose Find Usages.
    The XML Usages window opens in the lower part of the IDE.
  3. In the tree pane of the XML Usages window (the left pane), double-click the (Local Element) ... node.
    The IDE navigates to the Source view of the courier.xsd file and highlights the first line of the definition block for the element reference.
  4. Close the XML Usages window by clicking the close button in the window's title bar.

top


Applying a Design Pattern

You will now use the Design Pattern wizard to transform your XML schema file.

  1. In the Projects window, select and right-click the courier.xsd node and choose Apply Design Pattern from the pop-up menu.
    The Apply Design Pattern dialog box opens.
  2. Under Type, select the Do not Create Type(s) radio button and click Finish.
    This applies the Salami Slice pattern to your schema file.

top


Saving Your Work

You will now save your work before continuing with the next part of this workbook.

top


Adding the delivery XML Document File

To see how a schema is used, you will add an XML schema-constrained document file named delivery to your project.

  1. In the Projects window, expand the WebApplication project node.
  2. Expand the Source Packages node, right-click the <default packages node, and choose New > File/Folder.
    The New File wizard opens.
  3. In the Choose File Type page, in the Categories list, select the XML node, then in the File Types list, select XML Document and click Next.
  4. In the Name and Location page, in the File Name field, type delivery.
  5. Accept the other default values and click Next.
  6. In the Select Document Type page, select the XML Schema-Constrained Document radio button and click Next.
  7. In the Schema Options page, click the Browse button next to the Schema URI field.
  8. Navigate to path-to-project\WebApplication\src\java, select courier.xsd and click OK.
    The IDE has now filled in the fields of the Schema Options page.
  9. From the Root Element drop-down list, select delivery.
  10. Click Finish.
    The Source editor now has a tab for the delivery.xml file and that tab is the active tab.

top


Using Code Completion

As you type in the Source Editor, the IDE prompts you to choose from available schema elements and attributes. This saves time and reduces the chance of typographical errors.

  1. In the Source editor for the delivery.xml file, position your cursor just above the </delivery> line.
  2. Type a < (less than sign).
    The code completion box opens.
  3. Select courier and press Enter.
  4. Type the closing bracket (>).
  5. Select </courier> from the code completion box and press Enter.
  6. Position your cursor between the <courier> and </courier> tags and press Enter to insert a line.
  7. Type a < (less than sign).
    The code completion box opens.
  8. Select name and press Enter.
  9. Press the spacebar.
    The code completion box now opens with the list of attributes defined for name.
  10. Select first and press Enter.
  11. Press the spacebar.
    The code completion box opens with the list of attributes defined for name.
  12. Select last and press Enter.
  13. Type /> (forward slash followed by a greater than sign) to close the definition.
  14. Click the Save All toolbar button.
    You can also choose File > Save All from the IDE main menu.

top


Adding the schedule WSDL File

XML schema is often used by web services. You will now use the new WSDL file wizard to create a web service based on your XML schema file.

  1. In the Projects window, expand the WebApplication project node.
  2. Select the Web Pages node, right-click and choose New > File/Folder.
    The New File wizard opens.
  3. In the Choose File Type page, in the Categories list, select the Web Services node, then in the File Types list, select WSDL and click Next.
  4. In the Name and Location page, in the File Name field, type schedule.
  5. Select the Import XML Schema File(s) checkbox and click the Browse button to select src/java/courier.xsd.
  6. Click Next.
    The Abstract Configuration page opens.
  7. Under Input, in the Message Part Name column, change part1 to date and press Enter.
  8. Under Input, in the Element or Type column, click the ellipsis button.
    The Select Element or Type dialog box opens.
  9. Expand the BuiltIn Schema Types node, select the date node, and click OK.
    The type is now xsd:date.
  10. Under Output, in the Message Part Name column, change part1 to confirmed and press Enter.
  11. Click Finish.
    The Source editor now has a tab for the schedule.wsdl file and that tab is the active tab. The WSDL view is the active view in the WSDL editor.

top


Referencing an XML Schema File in the schedule WSDL File

Using elements defined in the XML schema, you can create new parts to the WSDL messages, specifying not only built-in types, but also those defined in imported files.

  1. From the IDE main menu, choose Window > Properties to open the Properties window.
  2. In the WSDL view, under the Messages node, select the scheduleOperationRequest, right-click and choose Add > Part from the pop-up menu.
    The IDE adds a subnode labeled part1.
  3. Select the new part1 node and in the Properties window, do the following:
    1. Change the Name property to customer.
    2. In the Element or Type property, click the ellipsis button.
      The customer [Part] - Element or Type dialog box opens.
    3. Expand the BuiltIn Schema Types node, and under the Built-in Types node, select the string node, and click OK.
      The type is now xsd:string.
  4. In the WSDL view, under the Messages node, select the scheduleOperationReply, right-click and choose Add > Part from the pop-up menu.
    The IDE adds a subnode labeled part1.
  5. Select the new part1 node and in the Properties window, do the following:
    1. Change the Name property to courier.
    2. In the Element or Type property, click the ellipsis button.
      The courier [Part] - Element or Type dialog box opens.
    3. Expand the Inline Schema Types > http://j2ee.netbeans.org/wsdl/schedule > Referenced Schemas > import > Elements nodes.
    4. Select the courier node and click OK.
      The type is now ns1:courier.

top


Using Validation

To ensure your document conforms to the defined standard, you can validate the file and check for any warnings or errors. If any problems were found, the output would provide hyperlinks directly to the offending line of code in the source editor.

top


More Documentation

top



Copyright and Trademark Notice