Referencing External XML Schemas

 

Support for referencing external XML Schemas is available only in Stylus Studio XML Professional Edition.

If you want, you can reference definitions from other XML Schemas in your XML Schema document. You might want to do this if you want to simply reuse existing definitions as-is, or if you wan to use an existing definition as the base for a type that you want to modify in your XML Schema.

This section covers the following topics:

Ways to Reference XML Schemas

There are three ways to reference XML Schema:

  • Including
  • Importing
  • Redefining

This section describes each of these techniques and how they can be used. In these descriptions, we use the term referenced XML Schema to indicate the XML Schema that is being included, imported, or redefined; and base XML Schema to indicate the XML Schema in which the referenced schema is being included, imported, or redefined.

Including an XML Schema

When reference an XML Schema by including it, the included XML Schema augments the base XML Schema. Both documents are effectively combined, and they both define the same XML Schema. complexTypes defined in the included XML Schema can be used as the base for new types - you might use a periodicals complexType from the included XML Schema to define weekly and quarterly types for example. Both the included XML Schema and the base XML Schema must have the same target namespace. You can include multiple XML Schemas in a base XML Schema.

Importing an XML Schema

When you reference an XML Schema by importing it, the base XML Schema and the imported XML Schema must have difference namespaces. The base XML Schema can the reference parts of the imported XML schema using a prefix whose namespace is defined in the imported XML Schema, for example. You can import multiple XML Schemas in a base XML Schema.

Redefining an XML Schema

Referencing an XML Schema by redefining it is similar to including it, with one important difference: when you redefine an XML Schema in the base XML Schema, you can redefine the definitions of the referenced XML Schema's complexTypes, simpleTypes, groups, and attributeGroups. For example, suppose you release version 1 of an XML Schema. When you need to release version 2 of the XML Schema, you can reference version 1 by redefining it in version 2, which allows you to change the definition of a given node to include a new attribute.

The original complexTypes, simpleTypes, groups, and attributeGroups in the redefined XML Schema are completely masked. They are redefined using extensions and restrictions. An extension extends the base type - declaring a new element, for example. A restriction constrains the base type.

Where You Can Reference XML Schemas

You can reference external XML Schemas in the Tree or Diagram tabs. In the text pane of the Diagram tab and the Tree tab, Stylus Studio displays the referenced XML Schema, but they do not display its contents. For example, in the Tree view, you cannot expand the node for an included XML Schema.

In the Diagram tab, Stylus Studio displays complete information for any definitions in referenced XML Schema. You can toggle between diagram views of the base and referenced XML Schemas using the definition browser.

Figure 258. You Can View Referenced Schemas

If you select a referenced schema from the definition browser, as shown in Figure 258, Stylus Studio changes the diagram view to display the referenced schema's structure. If you selected a redefined XML Schema, for example, you could modify its complexType definitions there.

What to Do Next

If you redefine an XML Schema (as opposed to including or importing one), you can redefine nodes after referencing the XML Schema. See Redefining Nodes for more information.

Referencing XML Schemas in the Diagram View

To reference an XML Schema in the Diagram view:
1. Right-click the schema node .
2. Click Referenced Schemas on the shortcut menu.

The Referenced Schemas dialog box appears.

Figure 259. Referenced Schemas Dialog Box

3. Click the Add button.

The Add References to Schema dialog box appears.

Figure 260. Add References to Schema Dialog Box

4. Specify the type of reference you want to make. If you are redefining an XML Schema, specify the namespace in the Namespace field.
5. Specify the URL of the XML Schema you want to reference. For example:
    • myfile.xsd
    • http://www.mycompany.com/schemas/myfile.xsd
    • \\fileserver\schemas\myfile.xsd
6. Click OK.

You are returned to the Referenced Schemas dialog box.

7. Click OK to add the referenced XML Schema to your XML Schema.

Referencing XML Schemas in the Tree View

To reference an XML Schema in the Tree view:
1. Click the Schema node.
2. In the XML Schema left-side tool bar, click one of the following:
    • New Include
    • New Import
    • New Redefine
3. In the field that Stylus Studio displays, enter the location. This is a URL that identifies the location of the file that contains the XML Schema. For example, it can be like any one of the following:
    • myfile.xsd
    • http://www.mycompany.com/schemas/myfile.xsd
    • \\fileserver\schemas\myfile.xsd
4. If you defined an Import node, in the Properties window, double-click the Target Namespace field and enter the target namespace. The target namespace must be different from the target namespace of the importing file.

Redefining Nodes

Once you reference an XML Schema by redefining it, you are able to redefine that XML Schema's complexTypes, simpleTypes, groups, and attributeGroups. This section describes how to redefine nodes using the Diagram tab.

Extensions and Restrictions

There are two ways to redefine a node: by extension and restriction. An extension extends the base type - adding an element or an attribute definition, for example. A restriction constrains the base type - limiting a type to a certain range of values, for example.

Specifying Restriction Facets

If you define a restriction using a simpleType, the Properties window displays a section that allows you to define the facets that restrict that type, as shown in Figure 261.

Figure 261. Facets for Describing Restrictions

Restriction facets include length, minLength, maxLength, and totalDigits. For each facet you specify, you provide the facet name, a value, and, for some facets, whether or not the value is fixed. Note that not all facets apply to all types.

See About Facet Types for simpleTypes for more information on facets.

How to Redefine a Node

To redefine a node in the Diagram view:
1. Right-click the schema node .
2. Select Redefine from the shortcut menu.

The Redefine Schema Symbols dialog box appears.

Figure 262. Redefine Schema Symbols Dialog Box

3. Select the node from the redefined XML Schema you want to redefine and click OK.

The redefined node is added to the diagram, and the text for the redefined node appears in the text pane. For example, <xsd:complexType name="PublicationType"/>.

4. Right-click the redefined node.
5. From the shortcut menu, select Quick Edit > and then either Derive by extension or Derive by restriction.

The Type Derivation dialog box appears.

Figure 263. Type Derivation Dialog Box

6. Select the base type from which you want to derive the definition of the node you are redefining. and click OK.

The node you added in Figure 3 is modified in the diagram to display the restriction or extension you are using to redefine it, as shown in Figure 264.

Figure 264. Redefined Node as a Restricted simpleType

The code displayed in the text pane is also modified. For example:

<xsd:complexType name="PublicationType">
               
   <xsd:simpleContent>
               
     <xsd:restriction base="SKU"/>
               
   </xsd:simpleContent>
               
</xsd:complexType>
               

            

7. If you specified a restriction of a simpleType, specify the restriction facets in the Properties window. See Specifying Restriction Facets if you need help with this step.
 
Free Stylus Studio XML Training: