
XML Schema Tools: Analyzing XML Schemas
Last Updated: 21 October 2006
Back to Getting Started With XML Schema Tools
The goal of this tutorial is to look at the different ways you can analyze XML schemas using queries available in XML schema tools.
Note: Wherever you see the icon, you can click to view a detailed interactive demonstration of the steps described in the tutorial.
top
Before You Start
Before you proceed to the analysis part of this tutorial, you must perform some preparation work. Make sure you complete the steps in this section before going to the next section, Finding Usages of a Schema Component.
The preparation tasks are:
- Add two complex types, HybridType and SportsCarType, to extend and restrict a complex type in the sample schema.
- Add an element substitution.
- Add a schema file.
To add the complex type components HybridType and SportsCarType:
- If mySchemaPrj is not open in the IDE, open it now and then open the newLoanApplication schema file.
- 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.
- In the Schema view, click the column button
to make sure you are in the column mode of the view.
- In the Schema view of the newLoanApplication schema file, right-click the Complex Types node and choose Add Complex Type.
The Complex Type dialog box opens.
- Do the following:
- In the Name field, type HybridType.
- 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.
- Under Global Reference, select the Restriction radio button, and in the list of types, expand the Complex Types node and select the CarType node.
Notice that the IDE shows you a preview of the source code that will be added for this definition.
- 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, HybridType; the node label also provides additional information: (restricts CarType).
View Demo
- In the Schema view of the newLoanApplication schema file, right-click the Complex Types node and choose Add Complex Type.
The Complex Type dialog box opens.
- Do the following:
- In the Name field, type SportsCarType.
- 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.
- Under Global Reference, select the Extension radio button, and in the list of types, expand the Complex Types node and select the CarType node.
- 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, SportsCarType; the node label also provides additional information: (extends CarType).
- From the IDE main menu, choose File > Save All.
View Demo
The Schema view now contains nodes for the complex types you added: HybridType and SportsCarType.
Note: If you have derivations in your schema, you can select the derivation, in this example, HybridType or SportsCarType, right-click and choose Go To > Definition to navigate directly to the source definition.
To add an element substitution:
- In the Schema view of the newLoanApplication schema file, click the Source button.
- In the Source view, add the following lines immediately before the last line of the file, the line that ends the schema definition:
<xs:element name="carLoanApplication" substitutionGroup="autoLoanApplication">
</xs:element>
- From the IDE main menu, choose File > Save All.
View Demo
To add a schema file:
- If mySchemaPrj is not open in the IDE, open it now.
- In the Projects window, expand the mySchemaPrj project node and expand the Source Packages node.
- Right-click the <default package> 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 Schema and click Next.
- In the Name and Location page of the wizard, in the File Name field, type newLoanHistory, accept the other default values (Folder: src, Target Namespace: http://xml.netbeans.org/schema/newLoanHistory) and click Finish.
In the Projects window, the <default package> node under the Source Packages node now contains a subnode labeled newLoanHistory.xsd. The newly created subnode is selected and the Source Editor contains a tab for the XML schema file, newLoanHistory.xsd.
- In the Schema view, click the Source button to go to the Source view of the schema file.
- In the Source view, replace the existing content with the sample code below.
<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://xml.netbeans.org/examples/targetNS"
xmlns:tns="http://xml.netbeans.org/examples/targetNS"
xmlns:la="http://xml.netbeans.org/examples/LoanApplication"
elementFormDefault="qualified">
<xsd:import namespace="http://xml.netbeans.org/examples/LoanApplication" schemaLocation="newLoanApplication.xsd"/>
<xsd:complexType name="PriorLoan">
<xsd:sequence>
<xsd:element name="Type" type="la:LoanType"></xsd:element>
<xsd:element name="State" type="la:StateType"></xsd:element>
</xsd:sequence>
</xsd:complexType>
<xsd:element name="History" type="tns:PriorLoan"></xsd:element>
</xsd:schema>
- From the IDE main menu, choose File > Save All.
View Demo
top
Finding Usages of a Schema Component
In this procedure, you will use the Find Usages command to display usages of a component in the two XML schema files in your project.
Note: The Find Usages command shows usages of a component in all XML schema, WSDL, and BPEL files in the current IDE project.
To find usages of a schema component:
- If mySchemaPrj is not open in the IDE, open it now and then open the newLoanApplication schema file.
- 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.
- In the Schema view, click the column button
to make sure you are in the column mode of the view.
- In the first column of the Schema view, select the Complex Types node.
- In the second column, select the AddressType node, right-click and choose Find Usages from the pop-up menu.
The IDE opens the XML Usages window in the lower part of the IDE. The XML Usages window has two panes, each with its own toolbar.
- The left pane, the usages pane, contains a tree that shows the usages of AddressType.
The toolbar buttons in this pane let you refresh information in the pane, expand and collapse nodes in the tree, and cycle through the found usages. Note that when you click the Refresh button in this pane, the IDE refreshes the data in both panes.
- The right pane, the graph pane, shows a graphical representation of the usages. If you resize the window or drag nodes outside of the pane, you can use the Layout toolbar button
in this pane to refresh the graph in the pane.

Productivity Tips
- In the graph pane, you can right-click a schema component, except the node that represents the queried component, and choose an option from the Go To menu to navigate directly to that component in the Source view, Schema view, or Design view. If the schema component is an extension or a restriction of another schema component, you can navigate directly to the extended or restricted schema component in the active view of the XML schema editor by choosing Definition from the Go To menu.
- Use the information below to zoom, pan, and drag the graph pane of the XML Refactoring window.
- To zoom out: right-click in the graphic and drag up.
- To zoom in: right-click in the graphic and drag down.
- To pan: click and drag in any direction.
- To drag a node: click and drag the node.
- If you drag a node out of the display area, you can bring it back using one of the following methods:
- Pan in the direction of the node until it is visible in the display area again.
- Zoom out until the node is visible in the display area.
- Click the Layout button
in the toolbar of the graph pane of the XML Usages window.
- To find usages of LoanType, do the following:
- In the first column of the Schema view of the newLoanApplication schema file, select the Simple Types node.
- In the second column of the view, select the LoanType node, right-click and choose Find Usages from the pop-up menu.
If the XML Usages window was still open, the IDE opens a Find XML Usages tab in the XML Usages window in the lower part of the IDE. The results show two file clouds with the file node and the usage nodes within the file clouds. You can double-click the file clouds to expand or collapse them and you can move a cloud with its content by dragging the cloud in the graph pane.
An illustration of the graph pane with the expanded newLoanHistory.xsd and collapsed newLoanApplication.xsd file clouds is shown below.

- Close the XML Usages window by clicking the Close button in the window's title bar.
View Demo
top
Finding Unused Global Components
In this procedure, you will use a query to find global components in the sample Loan Application Schema that are not used in any of the schema files in your project, mySchemaPrj.
This query allows you to identify top-level global elements when restructuring the schema towards a single root element (Venetian Blind design pattern).
To find unused global components:
- If mySchemaPrj is not open in the IDE, open it now.
- In the Projects window, select the newLoanApplication.xsd file node, right-click and choose Query > Find Unused Components.
A dialog box opens that lets you exclude global elements.
- In the dialog box, select the Exclude Global Elements checkbox and click OK.
The XML Schema Query window opens with a result tree. The query found five unused components: Borrow, HybridType, InternationalAddressType, and SportsCarType appear under the Complex Types node, and Lend appears under the Simple Types node, as shown in the following illustration.
The status bar also provides information about the query results.

- In the Projects window, select the newLoanApplication.xsd file node, right-click and choose Query > Find Unused Components.
A dialog box opens that lets you exclude global elements.
- In the dialog box, make sure the Exclude Global Elements checkbox is not selected and click OK.
The IDE opens a Find Unused tab in the XML Schema Query window with the results of the query. Notice that the results now include an Elements node, with one child node, carLoanApplication.

- In the Find Unused tab of the XML Schema Query window, select the carLoanApplication node, right-click and choose Go To Source.
The IDE opens the Source view and positions the cursor at the start of the block for the carLoanApplication element.
- Close the XML Schema Query window by clicking the Close button in the window's title bar.
View Demo
top
Finding Derivations of a Complex Type
In this procedure, you will use a query to find the derivations you created during the preparation phase of this tutorial.
To find derivations of a global complex type:
- In the Projects window, select the newLoanApplication.xsd file node, right-click and choose Query > Find Derivations of Complex Type.
The Find Derivations dialog box opens.
- In the list of complex types, select CarType and click OK.
The XML Schema Query opens with the result of your query. The derivations you just created for CarType are shown in the window.
The status bar provides additional information about the results: Found 1 extension and 1 restriction on CarType.

- Close the XML Schema Query window by clicking the Close button in the window's title bar.
View Demo
top
Finding Substitution Groups
In this procedure, you will use a query to find the element substitution you created during the preparation phase of this tutorial.
To find substitution groups:
- In the Projects window, select the newLoanApplication.xsd file node, right-click and choose Query > Find Substitution Groups.
The IDE shows the substitution you just created in the XML Schema Query window and also provides result information in the status bar (One Substitution Group Found). In this example, autoLoanApplication is the head element, and carLoanApplication can be substituted for autoLoanApplication.

- Close the XML Schema Query window by clicking the Close button in the window's title bar.
View Demo
top
Next Step
The steps in Retrieving and Referencing External XML Resources show you how to retrieve external resources into your IDE project and then reference those resources in your XML schema.
top
|
|