FeaturesPluginsDocs & SupportCommunityPartners

Working With XML Schemas Using the Design View

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.

Contents

Content on this page applies to NetBeans IDE 6.0

Tutorial Requirements

Before you proceed, make sure you review the requirements in this section.

Prerequisites

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:

  1. Open the mySchemaPrj project in the IDE.
  2. In the Projects window, expand the mySchemaPrj project node and expand the Source Packages node.
  3. Select the <default package> node, right-click and choose New > Other.
    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 designSchema.
  6. 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.

    New schema file added to project


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:

  1. If mySchemaPrj is not open in the IDE, open it now and then open the designSchema schema file.
  2. 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.
  3. In the Schema view, click the Design button to open the Design view.

    Initial view of Design view

    Note: If you do not see the Palette window, from the IDE main menu, choose Window > Palette.
  4. In the XML Components section of the Palette, click the Element icon 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.
    Drop allowed 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.
    Drop not allowed 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.
  5. Press Enter to accept the default name.
  6. Choose Window > Properties to open the Properties window.
    You will use the Properties window to change the name of the element.
  7. In the schema design area of the Design view, select newElement .
  8. In the Properties window, click the Name property, type Customer and press Enter.
    The IDE updates the Design view with the name you entered.

    Customer global element created

To add Name and Address elements to the Customer global element:

  1. In the XML Components section of the Palette, click the Element icon Element icon and drag it onto the Customer element.
    Notice that the IDE automatically adds a sequence component.
  2. Type Name and press Enter.
  3. In the XML Components section of the Palette, click the Element icon Element icon and drag it onto the Customer element.
  4. Type Address and press Enter.

    Name and Address elements added

To add Last and First attributes to the Name element in the Customer global element:

  1. In the XML Components section of the Palette, click the Attribute icon 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.
  2. Type Last and press Enter.
  3. In the XML Components section of the Palette, click the Attribute icon 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.
  4. Type First and press Enter.
  5. Click the Hide attributes icon, Hide attrbiutes, between the Name label and the attributes to hide the element's attributes.
    The icon changes to a Show attributes icon, Show attributes, which you can then click to show the attributes again.

    Last and First attributes added

To add Language as an attribute to the Customer global element:

  1. 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.
  2. Type Language and press Enter.

    Language attribute added to Customer global element

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:

  1. In the Design view, select the Language attribute of the Customer global element.
  2. Right-click and choose Properties from the pop-up menu.
    The Properties dialog box opens.
  3. 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.
  4. In the Built-in Types, select language.
  5. 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.

    Language attribute changed to language

To restrict schema components to accept only a string in the instance document:

  1. If the Properties window is not visible in the IDE, from the IDE main menu, choose Window > Properties.
  2. In the Design view, expand the Customer node and select the Name node.
  3. Hold down the Ctrl key and click the Address node to add the component to your selection.
  4. In the Properties window, click the ellipsis button in the Definition property.
    The Element's definition - Definition dialog box opens.
  5. Expand the Built-in Types node and select string.
  6. Click OK.
    The IDE updates the Definition property for the Name and Address components and also updates the Design view.

    Name and Address restricted to string

To save your changes:

  • In the Projects window, select the mySchemaPrj node and choose File > Save All.

top


Next Step

The steps in Analyzing XML Schemas show you how to use available queries in XML schema tools to analyze an XML schema.

You can also see the following:


top

Bookmark this page

del.icio.us furl simpy slashdot technorati digg
Companion
Projects:
MySQL Database Server   Open JDK: an Open SourceJDK   GlassFish Community: an Open Source Application Server    Mobile & Embedded Community    Open Solaris   java.net - The Source for Java Technology Collaboration   Virtual Box - full virtualizer  Open ESB - The Open Enterprise Service Bus Powered by