< Previous | Next >

Lesson 1.2: Add schema components

The XML schema editor provides the tools to easily generate XML schema components without possessing an in depth knowledge of XML schema semantics.

Before you begin, you must complete Lesson 1.1: Create your XML schema

The XML schema specification defines a large number of components such as complex types, simple types, groups, annotations, elements, attributes, and so on. To create a valid schema, you must understand the relationships between these components. For example, the <include>, <import> or <redefine> elements must appear before any other children of the schema element. An attribute can be added to a complex type, but not a simple type. There are many other relationships.

The XML schema editor removes the burden of remembering all these details. You can use the editor's Design view to add all of your schema components.

Add schema components

In these next steps, you will add several components to your schema, including simple and complex types, and global elements:

  1. The University.xsd file needs to contain a complex type for defining student information and a simple type for listing the faculties in the university:
    1. In the Design view, right-click the Types category, and click Add Complex Type.
    2. Click NewXSDComplexType, and change its name to Student.
    3. Right-click the Types category, and click Add Simple Type.
    4. Click XSDSimpleType, and change its name to Faculties.
  2. The Student complex type contains the student's name, the student's major, and the student's ID number. Add this information to the Student complex type by following these steps:
    1. To drill down to Student details, double-click the Student complex type.
    2. In the Student details view, right-click the Student complex type, and select Add Sequence. This will create a new content model object.
    3. In the Properties view, select all from the Kind drop-down list.
      Note: To view properties, click Window > Show View > Properties.
    4. Right-click the content model object, and click Add Element. A new element is created.
    5. Select the element and change its name to name. Note that the type of this element defaults to string.
    6. Right-click the Student complex type, and click Add Attribute. Change its name to id.
    7. Double-click the attribute type, and click int from the drop-down list.
    8. Right-click the content model object, and click Add Element. Change its name to major.
    9. Double-click the element type, and click Browse from the drop-down list.
    10. Select Faculties from the Types list, and click OK.
  3. The simple type, Faculties, is derived by restriction from the simple type string and its value is limited to one of the faculties in the university. To define this list, you will create the enumeration facet as follows:
    1. Select the Faculties simple type.
    2. In the Properties view, click the Constraints tab.
    3. Click Add and type the new enumeration science.
    4. Repeat steps a through c to create two more enumerations, arts and dentistry, for the Faculties simple type.
  4. To create an instance document from this XML schema, the XML schema must have a global element. You will now add a global element student as follows:
    1. In the Design view of the schema, right-click the Elements category and click Add Element. This will create a new element.
    2. Click NewElement, and change the name to student.
    3. Right-click the student element and select Set Type > Browse. Click Student from the Types list and click OK. Double-click the student element.
Your Design view should appear as shown below:
Design View

Lesson checkpoint

With the XML Schema editor it is possible to create valuable XML schema files without knowing all of the details and rules surrounding XML schema.

Now that you have finished, you should be able to complete the following:
  • Add components to your XML schema
  • Add information to a simple or complex type
  • Create the enumeration facet to define a list of restrictions for a simple type.
  • Add a global element to your XML schema
< Previous | Next >