< Previous | Next >

Lesson 1.3: Edit and validate your XML schema

Before you begin, you must complete Lesson 1.2: Add schema components.

Make changes and see how refactoring works

As a schema becomes bigger and more complex, it will have more type definitions, and references to those types. So what happens after you have defined a type, created ten references to that type, and you want to change the name of the type? The XML schema editor has a built-in refactoring mechanism that will propagate the changes automatically, meaning you do not have to do any manual updating. The following steps illustrate this feature.

In your University.xsd file, you have defined a simple type called Faculties. There is a reference to this type in the Student complex type. You have decided to change the name of the simple type to Faculty:

  1. In the Design view, right-click the Faculties simple type, and select Refactor > Rename.
  2. In the New name field, type Faculty and click OK.
  3. Now switch to the Source view (this view enables you to see your source code). Notice that the type for the element major is changed to tns:Faculty automatically.

Change the namespace prefix and target namespace

A namespace provides a way to identify where an element or attribute comes from.

In the University.xsd schema, the target namespace is http://www.example.org/University. This is indicated by the targetNamespace attribute in the schema element. This means that all the types that are defined in this schema belong to the target namespace http://www.example.org/University.

The following line in the schema element defines the prefix tns for this target namespace:
xmlns:tns="http://www.example.org/University"
To refer to a type defined in this schema, you must use this defined prefix. Look at the Source view and note how the major element and the student element refers to the type as follows:
<element name="major" type="tns:Faculty"/>
<element name="student" type="tns:Student"/>

If you want to change the namespace prefix or the target namespace for your schema, you can use the Design view. Follow these steps:

  1. In the Design view select the University schema.
  2. Go to the Properties view and change the Prefix to univ.
  3. Change the Target namespace to http://www.utoronto.ca.
  4. Look at the Source View. Note that the attributes for the schema element and all the prefixes for the types are automatically changed for you.
Your code should now look similar to this:
Source View

Validate your schema

Another useful feature of the XML schema editor is the incremental validation feature. After you save your XML schema file, you can right-click it in the Navigator view and click Validate. Any validation errors are reported in the Problems view with a red marker for the corresponding line in the Source view.

Lesson checkpoint

XML Schema Editor provides the tools to easily make changes which affect multiple dependencies, in a single step. In addition, the editor provides simple methods to specify namespace details, and verify file syntax.

In this lesson, you learned how to perform the following actions:
  • Make changes and see how refactoring works
  • Change the namespace prefix and target namespace
  • Validate your XML schema
< Previous | Next >