XML Schema Tools: Populating XML Schemas Using the Design View
Last Updated: 20 October 2006
Back to Getting Started With XML Schema Tools
The goal of this tutorial is to populate a simple XML schema using the Design view of the XML schema editor. You will then change some of the components. The Design view is an author-by-example view that lets you quickly add elements and attributes without the need to modify the source.
Note: Wherever you see the
icon, you can click to view a detailed interactive demonstration of the steps described in the tutorial.
top
Adding a New XML Schema File
In this procedure, you will add a new XML schema file, designSchema, in the mySchemaPrj project.
To add a new XML schema file:
- Open the mySchemaPrj project in the IDE.
- In the Projects window, expand the mySchemaPrj project node and expand the Source Packages node.
- Select the <default package> 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 designSchema.
- Accept the other default values (Folder: src, Target Namespace: http://xml.netbeans.org/schema/designSchema), and click Finish.
In the Projects window, the <default package> node under the Source Packages node now contains a subnode labeled designSchema.xsd. The Source Editor contains a tab for the XML schema file, designSchema.xsd.
View Demo
top
Adding Components to the XML Schema
In this procedure, you will add elements and attributes to the XML schema file, designSchema.
To add a component to the XML schema:
- If mySchemaPrj is not open in the IDE, open it now and then open the designSchema schema file.
- 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.
- In the Schema view, click the Design button to open the Design view.

Note: If you do not see the Palette window, from the IDE main menu, choose Window > Palette.
- In the XML Components section of the Palette, click the Element icon
and drag it just below the Elements node in the schema design area.
The editor only allows drag-and-drop to relevant areas of the schema design area and provides you with visual clues to let you know where you are adding the component.
 |
If you drag the selection over a component node or between nodes where you can add the new component, the cursor changes to an arrow with a small rectangle. |
 |
If you drag the selection over a component node or between nodes where you cannot add the new component, the cursor changes to resemble a no entry sign. |
The editor also provides textual hints in the form of tooltips.
The IDE adds a newElement component below the Elements nodes in the schema design area.
- Press Enter to accept the default name.
- Choose Window > Properties to open the Properties window.
You will use the Properties window to change the name of the element.
- In the schema design area of the Design view, select newElement .
- In the Properties window, click the Name property, type Customer and press Enter.
The IDE updates the Design view with the name you entered.
View Demo
To add Name and Address elements to the Customer global element:
- In the XML Components section of the Palette, click the Element icon
and drag it onto the Customer element.
Notice that the IDE automatically adds a sequence component.
- Type Name and press Enter.
- In the XML Components section of the Palette, click the Element icon
and drag it onto the Customer element.
- Type Address and press Enter.
View Demo
To add Last and First attributes to the Name element in the Customer global element:
- In the XML Components section of the Palette, click the Attribute icon
and drag it onto the Name element.
The IDE adds an editable box to the right of the Name label in the Name node.
- Type Last and press Enter.
- In the XML Components section of the Palette, click the Attribute icon
and drag it onto the Name element.
The IDE adds an editable box to the right of the Last attribute label in the Name node.
- Type First and press Enter.
- Click the Hide attributes icon,
, between the Name label and the attributes to hide the element's attributes.
The icon changes to a Show attributes icon,
, which you can then click to show the attributes again.
View Demo
To add Language as an attribute to the Customer global element:
- In the schema design area, select the Customer global element, right-click and choose Add > Attribute from the pop-up menu.
The IDE adds an editable box to the right of the Customer label in the Customer node.
- Type Language and press Enter.
View Demo
top
Editing XML Schema Components
In this procedure, you will use the Properties dialog box and in-place editing to make changes to schema components.
To change the type of an attribute using the Properties dialog box:
- In the Design view, select the Language attribute of the Customer global element.
- Right-click and choose Properties from the pop-up menu.
The Properties dialog box opens.
- In the Definition property, click the ellipsis button.
The Attribute's definition - Definition dialog box opens. The Built-in Types node is expanded and the string node is selected.
- In the Built-in Types, select language.
- Click OK.
The IDE updates the Definition property for the Language attribute. The schema design area is updated to reflect the updated Definition property of the Language attribute.
View Demo
To restrict schema components to accept only a string in the instance document:
- If the Properties window is not visible in the IDE, from the IDE main menu, choose Window > Properties.
- In the Design view, expand the Customer node and select the Name node.
- Hold down the Ctrl key and click the Address node to add the component to your selection.
- In the Properties window, click the ellipsis button in the Definition property.
The Element's definition - Definition dialog box opens.
- Expand the Built-in Types node and select string.
- Click OK.
The IDE updates the Definition property for the Name and Address components.
View Demo
To save your changes:
- In the Projects window, select the mySchemaPrj node and choose File > Save All.
top
Next Step
The steps in Applying Design Patterns to XML Schema Files show you how to use the Design Pattern wizard to easily apply a schema design pattern to an XML schema file.
top