In the Schema Overview, you have already created a global element called Company. This element is to contain one Address element and an unlimited number of Person elements—its content model. Global components that can have content models are elements, complexTypes, and element groups.
In XMLSpy, the content model of a global component is displayed in the Content Model View of Schema View (screenshot below). To view and edit the content model of a global component, click the Display Diagram icon located to the left of the global component.
In this section, you will create the content model of the Company element.
Creating a basic content model
To create the content model of the Company element:
|1.||In the Schema Overview, click the Display Diagram icon of the Company element. This displays the content model of the Company element (screenshot below), which is currently empty. Alternatively, you can double-click the Company entry in the Components entry helper to display its content model.|
|2.||A content model consists of compositors and components. The compositors specify the relationship between two components. At this point of the Company content model, you must add a child compositor to the Company element in order to add a child element. To add a compositor, right-click the Company element. From the context menu that appears, select Add Child | Sequence. (Sequence, Choice, and All are the three compositors that can be used in a content model.)|
This inserts the Sequence compositor, which defines that the components that follow must appear in the specified sequence.
|3.||Right-click the Sequence compositor and select Add Child | Element. An unnamed element component is added.|
|4.||Enter Address as the name of the element, and confirm with Enter.|
|5.||Right-click the Sequence compositor again, select Add Child | Element. Name the newly created element component Person.|
You have so far defined a schema which allows for one address and one person per company. We need to increase the number of Person elements.
|6.||Right-click the Person element, and select Unbounded from the context menu. The Person element in the diagram now shows the number of allowed occurrences: 1 to infinity.|
Alternatively, in the Details Entry Helper, you can edit the minOcc and maxOcc fields to specify the allowed number of occurrences, in this case 1 and unbounded, respectively.
Adding additional levels to the content model structure
The basic content model you have created so far contains one level: a child level for the company element which contains the Address and Person elements. Now we will define the content of the Address element so it contains Name, Street, and City elements. This is a second level. Again we need to add a child compositor to the Address element, and then the element components themselves.
Do this as follows:
|1.||Right-click the Address element to open the context menu, and select Add Child | Sequence. This adds the Sequence compositor.|
|2.||Right-click the Sequence compositor, and select Add Child | Element. Name the newly created element component Name.|
Complex types, simple types, and XML Schema data types
Till this point, we have not explicitly defined any element type. Click the Text tab to display the Text View of your schema (listing below). You will notice that whenever a Sequence compositor was inserted, the xs:sequence element was inserted within the xs:complexType element. In short, the Company and Address elements, because they contain child elements, are complex types. A complex type element is one which contains attributes or elements.
Simple type elements, on the other hand, contain only text and have no attributes. Text can be strings, dates, numbers, etc. We want the Name child of Address to contain only text. It is a simple type, the text content of which we want to restrict to a string. We can do this using the XML Schema data type xs:string.
To define the Name element to be of this datatype:
|1.||Click the Schema tab to return to Schema View.|
|2.||Click the Name element to select it.|
|3.||In the Details Entry Helper, from the dropdown menu of the type combo box, select the xs:string entry.|
Note that both minOcc and maxOcc have a value of 1, showing that this element occurs only once.
The text representation of the Name element is as follows:
<xs:element name="Name" type="xs:string"/>
|Note:||A simple type element can have any one of several XML Schema data types. In all these cases, the icon indicating text-content appears in the element box.|