FeaturesPluginsDocs & SupportCommunityPartners

XML Schema Tools: Working With XML Schema Components

Back to Getting Started With XML Schema Tools

The goal of this tutorial is to add and edit schema components in the sample XML schema that you opened in the Opening a Sample XML Schema tutorial. In addition, you will review how to undo and redo editing actions.

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 Schema Component

In this section, you will add a complex type named InternationalAddressType using the Schema view, and then you will add an element named province to that complex type.

Note: References in a schema file are read-only and are editable only where they are defined. This may be in the same schema file or in a different schema file.

To add the InternationalAddressType complex type:

  1. If mySchemaPrj is not open in the IDE, open it now and then open the newLoanApplication schema file.
  2. Maximize the 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 column view of the Schema view.
  3. In the Schema view, click the column button Column button in Schema view to make sure you are in the column mode of the view.
  4. In the first column of the Schema view, select the Complex Types node, right-click and choose Add Complex Type.
    The Complex Type dialog box opens.
  5. In the Name field, type InternationalAddressType.
  6. Under Type Definition, select the Use Existing Definition radio button.
    The lower part of the dialog box changes to provide you with options to define the reference.
  7. Under Global Reference, select the Extension radio button, and in the list of types, expand the Complex Types node and select the AddressType node.
    Notice that the IDE shows you a preview of the source code that will be added for this definition.
  8. Click OK.
    The IDE adds a node for the new complex type. The label of the node is the name you entered in the Name field, InternationalAddressType.
    Tip: You can right-click the new node and choose Go To > Definition to navigate directly to AddressType, the schema component you extended.

View Demo

To add the province element to the InternationalAddressType complex type:

  1. In the Schema view, select the InternationalAddressType node you just created, right-click and choose Add > Element.
    The Element dialog box opens.
  2. In the Name field, type province.
  3. Under Type, select the Use Existing Type radio button and in the list, expand the Built-in Types node and select string.
  4. Click OK.
    The Schema view now contains a node for the new province element, whose parent is the sequence under the InternationalAddressType complex type you added earlier.
  5. From the IDE main menu, choose File > Save All.

View Demo

top


Editing a Schema Component

In this procedure, you will change the name of a schema component using the Properties window. To make a structural change to a schema component, you cannot use the Properties window. For a structural change, such as using a locally defined complex type instead of referencing an existing complex type for a schema component, you must use the customizer for that component.

To edit a schema component:

  1. If mySchemaPrj is not open in the IDE, open it now and then open the newLoanApplication schema file.
  2. Show the Properties window by choosing Window > Properties.
    Tip: To increase the space used for the XML schema editor and the Properties window, you can minimize the Projects, Files, and Runtime windows.
  3. In the Schema view, click the column button Column button in Schema view to make sure you are in the column mode of the view.
  4. In the first column of the Schema view, select the Complex Types node.
    The IDE adds a new column to the right of the column where you selected the node. This new column shows you the complex types defined in the schema.
    Note: When the IDE adds a new column, a horizontal scrollbar may appear at the bottom of the Schema view. Use this scrollbar to return to the leftmost columns in the view. You can also click a link in the breadcrumb area to retrace your steps in the view.
  5. In the second column, select the AddressType node, then select the sequence node in the next column, and then select the zip node in the next column.
    The IDE adds another column to the right that contains information about the zip element. The Properties window shows the properties of the zip schema element.
  6. In the Properties window, change the Name property value to postcode and press Enter.
    Note: If you wanted to change the structure of the element, you would click the ellipsis button in the Structure property to access the Local Element customizer.
  7. From the IDE main menu, choose File > Save All.

View Demo

top


Deleting a Schema Component

In this procedure, you will delete the province component you added earlier in this tutorial. In this exercise, you will use a simple delete command. You could also use the refactoring function to safely delete a component. Refactoring in a BPEL Module Project Using NetBeans Enterprise Pack walks you through the refactoring functionality in NetBeans Enterprise Pack.

To delete a schema component:

  1. If mySchemaPrj is not open in the IDE, open it now and then open the newLoanApplication schema file.
  2. In the Schema view, click the column button Column button in Schema view to make sure you are in the column mode of the view.
  3. In the first column of the Schema view, select the Complex Types node.
  4. In the second column, select the InternationalAddressType node, then select the sequence node in the next column, and then select the province node in the next column.
  5. Right-click and choose Delete from the pop-up menu.
    The IDE deletes province from the XML schema file.
  6. From the IDE main menu, choose File > Save All.

View Demo

top


Undoing and Redoing Actions

In this procedure you will try out the undo and redo actions while working with a schema in the Schema view.

To undo and redo actions:

  1. If mySchemaPrj is not open in the IDE, open it now and then open the newLoanApplication schema file.
  2. In the Schema view, click the column button Column button in Schema view to make sure you are in the column mode of the view.
  3. In the first column of the Schema view, select the Complex Types node, right-click and choose Add Complex Type.
    The Complex Type dialog box opens.
  4. In the Name field, type Borrow, accept the other defaults (Inline Definition and Sequence) and click OK.
    The second column of the Schema view now contains a Borrow node.
  5. Switch to the Source view by clicking the Source button at the top of the Schema view.
  6. In the Source view, add a simple type named Lend by entering the following lines just before the </xs:schema> line:
    <xs:simpleType name="Lend">
      <xs:list>
        <xs:simpleType>
          <xs:restriction base="xs:string"/>
        </xs:simpleType>
      </xs:list>
    </xs:simpleType>
    
    In the following illustration, lines 274-280 show the source code as you would see it after you add it in the Source view:

    Lend component added

    At this point, Borrow and Lend exist in both the Schema and Source views.
  7. Go back to the Schema view by clicking the Schema button and click the Simple Types node in the first column to verify that Lend appears under the Simple Types node.
  8. Undo your actions by doing the following:
    1. Click the Undo button on the toolbar or press Ctrl-Z.
      Lend disappears from the Schema view.
    2. Click the Undo button again, or press Ctrl-Z again.
      Click the Complex Types node in the first column of the Schema view and notice that the Borrow component is no longer in the schema.
  9. Switch to the Source view by clicking the Source button at the top of the Schema view and notice that the elements (Borrow and Lend) are no longer in the Source view.
  10. Redo your actions by doing the following:
    1. Go back to the Schema view by clicking the Schema button in the Source view and then click the Redo button on the toolbar or press Ctrl-Y.
      The Borrow complex type is added back into the Schema view.
    2. Click the Redo button again, or press Ctrl-Y again.
      Click the Simple Types node in the first column of the Schema view and notice that the Lend component is added back into the Schema view.
  11. Navigate back to the Source view to verify that both elements are back in the source.
  12. From the IDE main menu, choose File > Save All.

View Demo

top


Using Cut, Copy, and Paste

In these procedures, you will learn how to use the cut, copy, and paste functions in the XML schema editor.

Note: You can perform all cut, copy, and paste actions using the right-click pop-up menus, Edit menu options, and toolbar buttons.

To create a copy of an XML schema component using copy and paste:

  1. If mySchemaPrj is not open in the IDE, open it now and then open the newLoanApplication schema file.
  2. In the Schema view, click the column button Column button in Schema view to make sure you are in the column mode of the view.
  3. In the first column of the Schema view, select the Complex Types node.
  4. In the second column, select the OccupancyType node, then select the sequence node in the next column, and then select the type node in the next column.
  5. Right-click your selection and choose Copy from the pop-up menu.
  6. In the first column of the Schema view, select the Complex Types node.
  7. In the second column, select the ResidenceType node, then select the sequence node in the next column.
  8. Right-click your selection and choose Paste from the pop-up menu.
    The type component now exists in both OccupancyType and ResidenceType.
  9. From the IDE main menu, choose File > Save All.

View Demo

To move an XML schema component using cut and paste:

  1. If mySchemaPrj is not open in the IDE, open it now and then open the newLoanApplication schema file.
  2. In the Schema view, click the tree button Tree button in Schema view to make sure you are in the tree mode of the view.
  3. In the first column of the Schema view, expand the Elements node, then expand the autoLoanApplication node.
  4. Under the autoLoanApplication node, select the annotation node, right-click and choose Cut from the pop-up menu.
  5. Under the autoLoanApplication node, expand the complexType node.
  6. Select the sequence node, right-click and choose Paste from the pop-up menu.
    The annotation now appears under the sequence node.
  7. From the IDE main menu, choose File > Save All.

View Demo

top


Using Drag-and-Drop

In this procedure, you will learn how to use the drag-and-drop functionality to reorder schema components. You will use the tree mode of the Schema view to perform the steps in this section.

Drag-and-drop reordering only works for child-level components. For example, you cannot use drag-and-drop functionality to reorder simple types in an XML schema, but you can use drag-and-drop functionality to reorder child components of a simple type definition in an XML schema.

To use drag-and-drop functionality:

  1. If mySchemaPrj is not open in the IDE, open it now and then open the newLoanApplication schema file.
  2. In the Schema view, click the tree button Tree button in Schema view to make sure you are in the tree mode of the view.
  3. In the Schema view, expand the Simple Types node, and then expand the LoanType node.
  4. Select the "refinance" node and drag it to just below the "new" node.
    The IDE moves the "refinance" to its new location.
  5. From the IDE main menu, choose File > Save All.

View Demo

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.



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   Open ESB - The Open Enterprise Service Bus Powered by