As an XML-based metalanguage for structuring XML documents, the XML Schema describes constraints that govern the order and sequence of elements and specifies permissible value spaces for all data used inside the content model. XML Schema is a full recommendation from the World Wide Web Consortium (W3C) and has massive industry support—clearly, it is meant to be the successor of the DTD because no future versions of DTDs are planned. I believe that the majority of future content-model development will be done using XML Schema. Therefore, this chapter is a critical topic for XML developers.
XML Schema 1.0 is the result of more than two years of work by the W3C group working on XML Schema. If you have worked with an earlier beta version of XML Schema, XMLSPY can convert XML Schemas based on the April 7th 2000 Working Draft or on the Oct. 24th Candidate Recommendation that concerns XML Schemas conforming to the XML Schema 1.0 final recommendation.
To help you become familiar with navigating XMLSPY’s Schema/WSDL Design view (Schema Design view for short), take a look at the prebuilt Purchase Order Schema shown in Figure 4-1. To access this schema, double-click order.xsd in the ch4 folder.
On the CD All example files used in this chapter are available in the XMLSPY Handbook Project, which installs itself as the default project if you are using the exclusive version of XMLSPY included with this book. If you are not using the version of XMLSPY from the CD (perhaps you downloaded a version from the Web), you can still access the example files. Simply locate the XMLSPYHandbook.spp file on the CD and copy it, along with all subdirectories, to your local file system. Then open the file by choosing Project → Open Project. The files used in this chapter are located in the ch4 folder.
Figure 4-1: The XMLSPY Schema Overview page.
Schema Design view is the default view when you open an XML Schema (.xsd is the file extension for XML Schemas). Just like any other XML document, however, you can also view XML Schemas in both Text view and Enhanced Grid view. Edits made in one view are synchronized with all other views. To change the default view associated with a particular file type, choose Tools → Options → File Types.
It is important to point out that only XML Schemas (and WSDL files that use some XML Schema syntax) can be viewed in Schema Design view. Attempting to view any other type of XML document in Schema view results in the error message Unable to show schema. In the Purchase Order Schema displayed in Figure 4-1, the Entry Helper windows on the right side are still there. They are usually used to display information about elements, attributes, and entities; in this case, however, they display more XML Schema–specific information, including information about components, details, and facets, as shown in Figure 4-2. All these properties will be discussed in the next few sections.
Figure 4-2: XML Schema–specific Entry Helper windows in the Schema Overview page.
In the main editing area (the center region of Figure 4-1), XMLSPY displays a tabular listing of all schema components, such as globally defined elements and attributes that are defined in the schema—in this case Order, AddressType, ProductType, and Note. The schema components section of the Schema Overview page is shown in Figure 4-3.
Figure 4-3: XMLSPY’s Schema Overview page displays a tabular listing of all the XML Schema components defined in the current XML Schema file.
To view or graphically edit a particular XML Schema component, click the tree button that appears immediately to the left of each schema component name (labeled as View Graphical Representation of Schema Component in Figure 4-3). For example, if you click the tree button adjacent to the ProductType schema component, you see the ProductType component in a graphical editing view.
Throughout this book, whenever I want you to view or edit an XML Schema component in a graphical tree view, I simply ask you to expand the schema element. When you stumble across this instruction, click the tree button next to the indicated component to view it graphically. I refer to the editable, graphical view of an XML Schema simply as Schema Editing view.
In the Schema Editing view (available after you expand a component listed on the Schema Overview page), an XML Schema component is displayed as one or more colored boxes and connecting lines. Elements are displayed as rectangles, and attributes for a selected element are listed in the Attributes window located immediately below the schema diagram (see Figure 4-4). Entity declarations, per se, are not supported in the XML Schema. However, some other XML Schema language constructs discussed later in this chapter can be used in a similar way to entity declarations. An XML Schema component resembles a tree whose branches can be expanded or collapsed in Schema Editing view. Within the Schema Editing view, nodes can be expanded or collapsed by clicking on the plus (+) or minus (–) signs that appear on each side of each compositor. The compositor is the connector that specifies a relationship between parent and child elements.
Figure 4-4 shows the ProductType global complex element. It is a sequence of five elements—Description, Price, Quantity, Ship-Date, and Note. Both Ship-Date, and Note are drawn using broken (dotted) rectangular boarders and connecting lines, signifying that they are optional elements. Also, the Note element is a reference to a global element defined outside the ProductType definition; this is denoted by a little arrow button inside the Note element. By contrast, all other elements are defined locally within the ProductType definition. To navigate back to the Schema Overview page, click the Back button located at the top-left corner of Figure 4-4.
Figure 4-4: Viewing the ProductType schema component in the Schema Editing view.
In Figure 4-4, I have configured Schema Editing view to display additional data type information for each element; this is displayed inside their respective element box diagrams. I talk more about changing the Schema Editing view’s configuration later in the chapter. Briefly, you customize the configuration by choosing Schema Design → View Config. The Schema Display Configuration panel appears. There are two possible ways to configure an XML Schema diagram to display additional information:
Click the Predefined button, which will load some default schema display settings (this is what I usually do).
If you want to manually specify exactly what details to show on an XML Schema diagram, click the Add New Entry button (toward the top-left of the panel) and a new row appears. Click the drop-down arrow and choose the kind of information you want to display (type, default, length, and so on). Repeat this until you have added the number of additional details you want to display on the schema diagram; then click OK.
Information about the currently selected element’s attributes (including the attribute’s type and default value) is displayed in the Attribute Overview pane at the bottom of Figure 4-4. The Attribute Overview pane also has buttons for inserting, appending, and deleting attributes for the currently selected element.
The Schema Design view consists of two pages: the Schema Overview page, which is a tabular listing of schema components defined in the current XML Schema, and the Schema Editing page, which is where you graphically edit a schema. To navigate from an XML Schema component viewed in the Schema Editing page back to the Schema Overview page, click the Back button located on the top-left side of the Schema Editing view. Throughout this book, when I ask you to return from the Schema Editing page to the Schema Overview page, simply click the Back button to do so.