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:
- NetBeans IDE 5.5 with NetBeans Enterprise Pack 5.5 (download)
- In this workbook, you will retrieve the UBL Order schema directly
from the Internet. If you want to step through this workbook offline,
you should download Java WSDP.
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.
- In the IDE, choose File > New Project.
- In the Categories list, select the Web node.
- In the Projects list, select Web Application and click Next.
- In the Name and Location page, in the Project Name field, enter WebApplication and specify the project location.
- 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.
- 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.
- Open the WebApplication project in the IDE.
- In the Projects window, expand the WebApplication project node.
- Select the Source Packages node, right-click and choose New > File/Folder.
The New File wizard opens.
- 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.
- In the Name and Location page of the wizard, in the File Name field, type courier.
- Accept the other default values and click Finish.
The new file, courier.xsd, is opened in the Schema view of the XML schema editor.
- 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.
- 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.
- Add a global complex type named CourierType by doing the following:
- 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.
- Type CourierType and press Enter.
- Add an element named name to the CourierType complex type by doing the following:
- 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.
- Type name and press Enter.
- Add two more elements (startDate and vehicle) to the CourierType complex type by doing the following:
- In the XML Components section of the Palette, click the Element icon and drag it onto the courierType complex type.
- Type startDate and press Enter.
- In the XML Components section of the Palette, click the Element icon and drag it onto the courierType complex type.
- Type vehicle and press Enter.
- Add two attributes (first and last) to the name element by doing the following:
- In the XML Components section of the Palette, click the Attribute icon and drag it onto the name element.
- Type first and press Enter.
- In the XML Components section of the Palette, click the Attribute icon and drag it onto the name element.
- 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.
- In the Design view, click the Schema button to switch to the Schema view.
- In the Schema view, click the tree button
to switch to the tree mode of the view.
- 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.
- Click in the Find box, type startDate, and press Enter.
The IDE selects the first matching occurrence (as it appears in the source).
- Close the Find bar by clicking the red "x" icon
in the Find bar.
- In the Schema view, right-click the startDate node and choose Customize from the pop-up menu.
The Local Element Customizer dialog box opens.
- 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.
- 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.
- In the Name field, type courier.
- Under Type, select the Use Existing Type radio button and in the list, expand the Complex Types node.
- 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.
- If the Output window is not visible, choose Window > Output.
When the IDE retrieves the resources, informational messages appear in the Output window.
- In the Projects window, expand the WebApplication project node and expand the Source Packages node.
- Select the Source Packages node, right-click and choose New > File/Folder.
- In the New File dialog box, under Categories, select the XML node, and in the File Types list, select External XML Schema Document.
- Click Next.
The New Retrieve Documents page opens.
- In the Specify Resource Location page, do the following:
- Select the From URL radio button.
- 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.
- 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.
- 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.
- 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.
- 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.
- 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.
- In the Schema view, select the Elements node, right-click, and choose Add Element from the pop-up menu.
The Element dialog box opens.
- In the Name field, type delivery.
- 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.
- 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.
- Expand the Referenced Schemas node > import node > Elements node.
- Select the Order node and click OK.
The IDE has added the element reference. It has the following label: Order [1..1](->) node.
- 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.
- Expand the Elements node.
- 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.
- 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.
- 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.
- 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.
- 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.
- 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.
- 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.
- Click the Save All toolbar button.
You can also choose File > Save All from the IDE main menu.
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.
- In the Projects window, expand the WebApplication project node.
- Expand the Source Packages node, right-click the <default packages node, and choose New > File/Folder.
The New File wizard opens.
- 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.
- In the Name and Location page, in the File Name field, type delivery.
- Accept the other default values and click Next.
- In the Select Document Type page, select the XML Schema-Constrained Document radio button and click Next.
- In the Schema Options page, click the Browse button next to the Schema URI field.
- 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.
- From the Root Element drop-down list, select delivery.
- 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.
- In the Source editor for the delivery.xml file, position your cursor just above the </delivery> line.
- Type a < (less than sign).
The code completion box opens.
- Select courier and press Enter.
- Type the closing bracket (>).
- Select </courier> from the code completion box and press Enter.
- Position your cursor between the <courier> and </courier> tags and press Enter to insert a line.
- Type a < (less than sign).
The code completion box opens.
- Select name and press Enter.
- Press the spacebar.
The code completion box now opens with the list of attributes defined for name.
- Select first and press Enter.
- Press the spacebar.
The code completion box opens with the list of attributes defined for name.
- Select last and press Enter.
- Type /> (forward slash followed by a greater than sign) to close the definition.
- 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.
- In the Projects window, expand the WebApplication project node.
- Select the Web Pages node, right-click and choose New > File/Folder.
The New File wizard opens.
- 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.
- In the Name and Location page, in the File Name field, type schedule.
- Select the Import XML Schema File(s) checkbox and click the Browse button to select src/java/courier.xsd.
- Click Next.
The Abstract Configuration page opens.
- Under Input, in the Message Part Name column, change part1 to date and press Enter.
- Under Input, in the Element or Type column, click the ellipsis button.
The Select Element or Type dialog box opens.
- Expand the BuiltIn Schema Types node, select the date node, and click OK.
The type is now xsd:date.
- Under Output, in the Message Part Name column, change part1 to confirmed and press Enter.
- 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.
- From the IDE main menu, choose Window > Properties to open the Properties window.
- 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.
- Select the new part1 node and in the Properties window, do the following:
- Change the Name property to customer.
- In the Element or Type property, click the ellipsis button.
The customer [Part] - Element or Type dialog box opens.
- 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.
- 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.
- Select the new part1 node and in the Properties window, do the following:
- Change the Name property to courier.
- In the Element or Type property, click the ellipsis button.
The courier [Part] - Element or Type dialog box opens.
- Expand the Inline Schema Types > http://j2ee.netbeans.org/wsdl/schedule > Referenced Schemas > import > Elements nodes.
- 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.
- Click the Validate XML
button.
Validation results appear in the Output window.
top
More Documentation
top
Copyright and Trademark Notice