# Referential integrity in the XML schema editor

When you define a complex type, you can add a content model to it and reference a global element.

For example:

    <schema>
        <element name="comment" type="string">
        <complexType name="Items">
            <sequence>
                   <element ref="comment">
            </sequence>
        </complexType>
    </schema>

If the global element (comment) was deleted, all references to it would be in error. To prevent this, the XML schema editor has a built-in mechanism to handle such referential integrity issues. When you delete the global element, the XML schema editor will clean up using the following algorithm:

- If there are one or more global elements in the schema, it will change all existing references to the first global element.
- If there is no global element, then it will delete the element reference from the content model.

Similar cleanup operations are performed when other types of objects are deleted. The following lists describes various cleanup operations.

Deleting a global attribute will cause the following cleanup:

1. Any content model or attribute group that references the deleted global attribute will be reset using the above algorithm.

Deleting a complex type will cause the following cleanup:

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 cleanup:

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 a group or attribute group will cause the following cleanup:

1. Any complex type that references the deleted group or attribute group will be reset using the algorithm similar to the one described earlier for deleted global elements.

#### Deleting include and import elements

When an `include` or `import` element is added to a schema, types from the included or imported schema become visible to the current schema. 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>

If the included schema is subsequently deleted, the `include` element would be in error. To prevent this, the XML schema editor will perform the necessary cleanup. In this example, the type for the element `shipTo` would be reset to the `string` data type.

The XML schema editor resets the following type references when an include or import element is deleted:

- Global element and element's type
- Attribute type
- Complex type derivation
- Simple type derivation

The cleanup is similar to the other operations outlined above. The XML schema editor will write an information message to the Problems view to notify you of such operations.

(c) Copyright 2001, World Wide Web Consortium (Massachusetts Institute of Technology, Institut National de Recherche en Informatique et en Automatique, Keio University)

(C) Copyright IBM Corporation 2000, 2005. All Rights Reserved.