Analyzing XML Schemas
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.
Contents
Tutorial Requirements
Before you proceed, make sure you review the requirements in this section.
Prerequisites
The XML schema tools tutorials assume that you have some knowledge of, and experience with XML (Extensible Markup Language).
Software Needed for This Tutorial
Before you begin, you need to install the following software on your computer:
- NetBeans 6.0
Select the Download All option. The Download All option includes SOA Pack and GlassFish V2, which are required for this tutorial.
You should be familiar with the following tutorials:
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 Unused Global Components.
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).
- 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.
The Schema view now contains nodes for the complex types you added: HybridType and SportsCarType. In the following illustration, the new complex types are highlighted.

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.
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 > Other.
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.
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 places the results from the first query in a Find Unused tab and adds a new Find Unused tab in the XML Schema Query window with the results of this query. Notice that the results now include an Elements node, with one child node, carLoanApplication.

- In the top 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.
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.
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.
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.
You can also see the following:
top