XML Schema Editor Advanced Features

This section covers some of the more advanced features in the XML Schema Editor.

Including and Importing Types

As schemas become larger, it is often desirable to divide their content among several schema documents for purposes such as ease of maintenance, reuse, and readability. XML Schema defines two constructs to support this: include and import. The include element brings in definitions and declarations from the included schema into the current schema. It requires the included schema to be in the same target namespace as the including schema. The import element behaves in a similar way, with the exception that the imported schema can come from a different namespace.

Including Types

In the XML Schema Editor, on an XML Schema file object, you can select Add Include to add an include element.

In the Design View for the include element, you must specify the name of the included XSD file, for example: F:\vabase\itp\workbench\B2B\Project1\Address.xsd. This XSD file must have the same namespace as the current schema. The result include element will look like this:

<include schemaLocation="F:\vabase\itp\workbench\B2B\Project1\Address.xsd"/>
Once the include element is added, when you define new elements, attributes, complex types, or simple types whereby you can specify type information, the declarations from the included schema will be available in the type drop-down combo-box for your selection.

For example, if Address.xsd has the following content:

<complexType name="Address">
    <sequence>
        <element name="name" type="string">
        <element name="street" type="string">
    </sequence>
</complexType>
And if PurchaseOrder.xsd has added an include for Address.xsd, then when defining a new element in PurchaseOrder, you can select Address as its type.

Importing Types

In the XML Schema Editor, on an XML Schema file object, you can select Add Import to add an import element. An import element is always added to the top of the schema file, as it must appear as the first children of the schema element.

In the Design View for the import element, you must specify the name of the imported XSD file in the Schema Location field, for example: F:\vabase\itp\workbench\B2B\Project1\Address.xsd. The XML Schema Editor will retrieve the namespace for the Address.xsd and display that as read-only in the Namespace field, for example, http://www.ibm.com. You need to specify a unique prefix for this namespace in the Prefix field, for example, po.

Assuming you entered the above data, the result schema element, and  import element will look like this:

<schema ...
    xmlns:po="http://www.ibm.com">
<import namespace="http://www.ibm.com"
        schemaLocation="F:\vabase\itp\workbench\B2B\Project1\Address.xsd"/>
Once the import element is added, when you define new elements, attributes, complex types, or simple types whereby you can specify type information, the declarations from the imported schema will be available in the type drop-down combo-box for your selection.


Referential Integrity

When you define a complex type, you can reference a global element in the schema. For example:
<schema>
    <element name="comment" type="string">
    <complexType name="Items">
        <sequence>
               <element ref="comment">
        </sequence>
    </complexType>
</schema>
So what happen if the user deletes the global element comment? The XML Schema Editor has built-in mechanism to handle such referential integrity issues. When you delete the global element, the XML Schema Editor will perform clean up using the following algorithm: In addition, the XML Schema Editor will write an information message to the Task List to notify the user of such operations.

The following lists all the possible propagations that can happen when an object is deleted:

Deleting a global element will cause the following clean up:

  1. Any complex type that references the deleted global element will be reset using the above algorithm.
  2. Any element that has a substitution group that is set to the deleted global element will be reset to empty.
Deleting a complex type will cause the following clean up:
  1. Any element type that is set to the deleted complex type will be reset to the string type.
  2. Any complex type that derives from the deleted complex type will be reset to no derivation.
Deleting a simple type will cause the following clean up:
  1. Any attribute type that is set to the deleted simple type will be reset to the string type.
  2. Any element type that is set to the deleted simple type will be reset to the string type.
  3. Any simple type that derives from the deleted simple type will be reset to string as its base type.
Deleting an attribute group will cause the following clean up:
  1. Any complex that references the deleted attribute group will be reset using the algorithm similar to the one described earlier.
Deleting a group will cause the following clean up:
  1. Any content model that references the deleted group will be reset.

Deleting includes and imports

As discussed earlier, once an include or import is added to a schema, types from the included or imported schema become visible to the current schema when adding new constructs. For example, the following schema references the Address type from the Address.xsd file

<schema targetNamespace="http://www.example.com/IPO"
              xmlns="http://www.w3.org/1999/XMLSchema"
              xmlns:ipo="http://www.example.com/IPO>
    <include schemaLocation="F:\vabase\itp\workbench\B2B\Project1\Address.xsd"/>
    <complexType name="PurchaseOrder">
            <sequence>
                    <element name="shipTo" type="ipo:Address">
            </sequence>
    </complexType>
</schema>

So what happen if the user deletes the include element? The XML Schema Editor will perform the necessary cleanup. In this example, the type for the element shipTo will be reset to the string data type.

The XML Schema Editor resets the following type references when an include or import element is deleted. The rules are similar to the propagation scenarios outlined earlier.

The XML Schema Editor will write an information message to the Task List to notify the user of such operations.