XML Schema Editor Tutorial

This tutorial will show you how to create a XML Schema (XSD) using the XML Schema Editor. We will create a new XSD for a Purchase Order. Before you begin this tutorial, you might want to review the XML Schema Part 0: Primer to learn about XML Schema. The Purchase Order we create below will contain the similar information as the first example that is specified in the Primer.

Setup

Before you start this tutorial, make sure you have created a solution and a project. In the following example, we assume the B2B/MyProject project is created. Also, under Perspective, switch to the XML Perspective. The completed example is located in plugins/xsdeditor/samples/PurchaseOrder/PurchaseOrder.xsd.

Getting Started

From the Workbench, choose New->XML Schema. The Create XSD Schema wizard will come up. Specify an XSD name, such as PurchaseOrder.xsd.

When you say Finish, a PurchaseOrder.xsd resource will be created under B2B/MyProject in the Navigator view. You can double click on the PurchaseOrder.xsd to open the XML Schema Editor.

The Content Outline view will show you all the items in your XSD as you add them. You will notice the PurchaseOrder file object. The right hand side of the window is a detailed Design View and Source View for the XSD.

Creating the structure of the XSD

Adding Annotation

We will first add a comment to the Purchase Order schema:

Adding Global Elements

Next we will add two global elements to the Purchase Order schema:

Adding Complex Types

Next we will add three complex types to the Purchase Order schema:

Adding Simple Type

Next we will add a simple type to the Purchase Order schema.

Filling in the details

Now that we have created the general outline for the XML Schema, we will go back to each object to fill in the details.

Click on the PurchaseOrder documentation object. In the Comment data entry field, enter some comments, similar to the Purchase Order example from the Primer.

Click on the purchaseOrder global element. Change the type to User-defined Complex Type, and select PurchaseOrderType as its type.

Right mouse button 2 on the complex type PurchaseOrderType. You will notice a number of menu items. We will use it to add the components to the PurchaseOrderType:

You have now completed the element declarations for PurchaseOrderType. We will now add an attribute declaration. Right mouse button 2 on the complex type USAddress. Similar to PurchaseOrderType, add in the sub-component for USAddress following the example in the Primer. The steps are similar to the PurchaseOrderType and therefore we will not repeat the description.

Right mouse button 2 on the complex type Items. The Items complex type has a number of interesting aspect. It uses anonymous types, so we will go through the steps in some detail:

Click on the simple type Sku. We want to derive its type from a built-in type and apply constrain to its value. We have now completed our Purchase Order schema. Your XML Schema outline looks something like the screen capture below. You can choose Validate XML Schema to validate this XSD against the W3C schema dtds.

Viewing the XSD Source

At any time, you can switch to the Source tab to review the source for the XML Schema.

Saving the XSD Model

At any point in time, you can save the XSD. Select File->Save PurchaseOrder.xsd from the file menu to save it.