xml spy
Previous  Top  Next
Adding elements to a schema

To add elements to a schema:
1.Click the component icon ic_component next to the Company element, in the main window, to display the content model (or double click on the Company entry in the Component Navigator).  
The text below the company element is annotation text. Double click the text if you want to edit it. (shortened to "Root element" here.)  
2.Right click the Company element to open the context menu, and select Add Child | Sequence.  

tut_7a  

This inserts the Sequence compositor, and defines that the following elements must appear in the same sequence (in the XML document).  

tut_7b  

3.Right click the Sequence compositor and select Add Child | Element.  
4.Enter "Address" as the name of the element, and confirm with the Enter key.  

tut_8a  

5.Right click the Sequence compositor again, select Add Child | Element, and enter "Person" as the name of the element.  

tut_8b  

We have now defined a schema which allows for one address and one person per company. As this is too restrictive, we want to make sure that we can include as many persons per company as necessary.  
 
6.   Right click the Person element, and select Unbounded from the context menu.  
The Person element changes at this point, showing the range in which it can occur, in this case 1 to infinity.  

tut_8c  

Please note:  
You can also edit the minOcc and maxOcc fields in the Details entry helper directly.  
 
We will now add the sub-elements which define the address structure.  
 
To add sub-elements to an element:
1.Right click the Address element to open the context menu, and select Add Child | Sequence.  
2.Right click the Sequence compositor, and select Add Child | Element. Enter "Name" as the element name.  
 
tut_9a  

Defining element parameters:

At this point we want to define that the Name element is to occur only once, and contain only textual data.

1.Click the Name element, if not currently selected.  
2.Click on the type combo box of the middle entry helper, and select the entry xs:string from the drop down list.  

tut_9b  

This entry helper is called "Details" in the Schema view, and provides information on the currently selected element. All data can be edited directly in the Details window!  
 
An icon appears in the top left of the element tut_9c, indicating that this element contains text.  

Both "minOcc" and "maxOcc" fields contain 1, showing that there is only one occurrence of this element (this is the default setting when creating a new element).  

tut_10a  

Previous  Top  Next

© 2002 Altova