xml spy
Previous  Top  Next
Globals, extending simple and complex types

Having defined an element, you may then realize that you want to reuse it somewhere else in your schema. In XML Spy this is achieved by creating a global component.

To create a global component:
1.Right click the Address element, and select Make Global | Complex type.  
The Address elements appear in a yellow box.  

tut_17a  
2.Click on the "Display all Globals" ic_back2global icon.  
The schema overview now displays two global components: the Company element and the complexType "AddressType".  

tut_17b  

Click on the Com(plex) tab of the Component Navigator to see that AddressType is also visible there.  
3.Click on the AddressType component icon ic_component, to see the content model.  

tut_18a  

4.Click the "Display all Globals" icon to return to the schema overview.  
 
Extending a "complex type" definition
We now want to use the global AddressType component, to create two kinds of country specific addresses. For this purpose we will define a new complex type based on the AddressType component.

To extend a "complex type" definition:

1.Switch to the schema overview, if not already visible (Display all globals).  
2. Click the Append icon, at the top left of the component window.  
3. Select ComplexType from the context menu.  

tut_18b  

A new line appears in the component list, and the cursor is set for you to enter the component name.  
4.Enter "US-Address" and confirm with Enter. (If you forget to enter the hyphen character "-", the element name will appear in red, signalling an illegal character.)  

tut_18c  
5.Click the US-Address component icon ic_component to see the content model.  
6.Click the "base" combo box in the Details entry helper, and select the "AddressType" entry.  

tut_19a  

The content model view changes immediately and displays the previously defined generic address.  

tut_19b  

7.Right click the US-Address element, and select Add Child | Sequence.  
A new sequence compositor is displayed outside of the AddressType box. This is a visual indication that this is an extension to the element.  

tut_20a  

8.Right click the new sequence compositor, and select Add Child | Element.  
9.Name the element "Zip", and hit the "Tab" button.  
10.Select (or enter) xs:positiveInteger from the "type" field combo box, and confirm with Enter.  

tut_20b  

Creating reusable "simple type" elements
Simple type elements can also be made generic. In this case we want to make the State element reusable, so that an abbreviated version could also be included in address labels at a later time (GA for Georgia, for example).

To
create reusable "simple type" elements:
1.Switch to the Schema overview ic_back2global (Display all Globals).  
2.Click the append icon, select SimpleType, and enter "US-State" as the element name (Enter to confirm).  
3.Select xs:string in the "restr." value field of the Details entry helper.  
This completes the definition. This element can now be used in the US-Address definition.  

tut_21a  
4.Click the US-Address component icon ic_component, then right click the lower sequence compositor and select Add Child | Element.  
5.Enter "State" for the element name, and hit the "Tab" key.  
6.Select (or enter) "US-State" from the "type" combo box (click Enter to confirm).  

tut_21b  

Please note:  
Global simple types can only be created from the schema overview.  

Creating the second Address template
Using the method described above, define the global complex type "UK-Address".

1.Create the global complex type "UK-Address", with the base="AddressType"  
2.Add a new Postcode element to the content model of UK-Address.  

Your UK-Address content model should finally look like this:  

tut_22a  

Previous  Top  Next

© 2002 Altova