Defining a complexType in a Sample XML Schema in the Diagram View

This topic is part of a sequence that begins with Description of Sample XML Schema.

The steps for defining the PublicationType complexType described in Description of Sample XML Schema are presented in the following topics:

Defining the Name of a Sample complexType in the Diagram View

This topic is part of a sequence that begins with Description of Sample XML Schema.

To define a complexType in a sample XML Schema:
1. From the Stylus Studio menu bar, select File > New > XML Schema.

Stylus Studio displays the XML Schema Editor. Maximize the XML Schema Editor window. If the Project window is visible, you can close it.

2. At the bottom of the XML Schema editor, click the Diagram tab.

Stylus Studio displays the Diagram view for the new schema.

3. Right-click the schema node in the XML Schema diagram pane and select Add > ComplexType from the shortcut menu.

Alternatives: This action is also available from the XMLSchema > Grid Editing menu.

Stylus Studio displays a representation for the new node in the diagram. The complexType properties appear in the Properties window. The new complexType has a default name of ComplexType-0.

Stylus Studio updates the diagram and the XML Schema in the text pane.

5. Click Save .
6. In the Save As dialog box, in the URL field, type bookstoreDiagram.xsd, and click Save. You can save it in the examples directory of the Stylus Studio installation directory or in a directory of your choice.

Adding an Attribute to a Sample complexType in the Diagram View

This topic is part of a sequence that begins with Description of Sample XML Schema.

To add the genre attribute to the PublicationType complexType:
1. Right-click the PublicationType node.
2. In the shortcut menu that appears, select Add > Attribute.

Stylus Studio displays a node for the new attribute (untitled).

3. In the Properties window, type genre as the name of the new attribute and press Enter.
4. In the Properties window, click the Type field.

Stylus Studio displays a drop-down list of built-in types.

5. Scroll down to xsd:string and click it, or type xsd:string and press Enter.

The diagram should now look like the one shown in Figure 69

.

Adding Elements to a Sample complexType in the Diagram View

This topic is part of a sequence that begins with Description of Sample XML Schema.

The elements belonging to this complexType must occur in a specific order. Before defining the first element, you need to create a sequence node to define this requirement in the XML Schema.

To add the title element to the PublicationType complexType:
1. Right-click the PublicationType node.
2. In the shortcut menu that appears, select Add > Sequence.

The sequence node is added to bookstoreDiagram.xsd. The sequence modifier indicates that if an instance document contains the sequence node's child elements (the elements you will add next), they must be in the order in which they are defined.

3. Type title and press Enter.
4. Right-click the sequence node .
5. In the shortcut menu that appears, select Add > Element.

A child element is added to the PublicationType node.

6. In the Properties window, click the Name field and enter title.
7. In the Properties window, click the Type field.

Stylus Studio displays a drop-down list of built-in types.

8. Scroll down to xsd:string and click it, or type xsd:string and press Enter.

According to the XML Schema requirements described earlier, the title element can occur only once. By default, the default value for the Min Occur. (minimum occurrences) and Max Occur. (maximum occurrences) properties is 1. You want exactly one instance of the title element in PublicationType, so you can accept these defaults.

Adding Optional Elements to a Sample complexType in the Diagram View

This topic is part of a sequence that begins with Description of Sample XML Schema.

To add the optional subtitle element to the PublicationType complexType:
1. Right-click the sequence node .
2. In the shortcut menu that appears, select Add > Element.

Below the title element, Stylus Studio displays a rectangle for the new element definition.

3. Rename the new element subtitle.
4. Give the new element a data type of xsd:string.
5. Give the new element a minimum occurrences value of 0.

You can accept the default of 1 for the Max Occur. property.

6. Click Save .

At this point, the XML Schema diagram should look like Figure 70:

Adding an Element That Contains Subelements to a complexType in the Diagram View

This topic is part of a sequence that begins with Description of Sample XML Schema.

The sample schema requirements (see Description of Sample XML Schema) state that the PublicationType complexType must include at least one author element. Further, an author element must include a first-name element and a last-name element.

Each element that can contain one or more subelements is a complexType. Consequently, to add the author element to the PublicationType complexType, you must first define the AuthorType complexType. You can then add an element that is of AuthorType to the PublicationType complexType.

To define the AuthorType complexType:
1. Right-click the schema node in the XML Schema diagram pane and select Add > ComplexType from the shortcut menu.

Alternatives: This action is also available from the XMLSchema > Grid Editing menu.

Stylus Studio displays a representation for the new node in the diagram. The complexType properties appear in the Properties window.

2. Type AuthorType in the Name property in the Properties window and press Enter.

Stylus Studio updates the diagram and the XML Schema in the text pane.

3. Right-click the AuthorType node in the diagram.
4. In the shortcut menu that appears, select Add > Sequence.

Stylus Studio displays the sequence node .

5. Right-click the sequence node.
6. In the shortcut menu that appears, select Add > Element.
7. Type first-name in the Name property in the Properties window and press Enter.
8. Change the Type property to xsd:string and press Enter.
9. Repeat step 5 through step 8 to add a new element to the sequence, using last-name as the name of the new element.
Now you can add the author element to the PublicationType complexType:
1. Right-click the sequence node belonging to the PublicationType node.
2. In the shortcut menu that appears, select Add > Element.

Stylus Studio displays a representation for the new node in the diagram. The complexType properties appear in the Properties window.

3. Type author in the Name property in the Properties window and press Enter.

Stylus Studio updates the diagram and the XML Schema in the text pane.

4. Click the Type field in the Properties window. Stylus Studio displays a drop-down list of built-in types plus any types you have defined, such as the AuthorType you defined in the previous procedure.
5. Select AuthorType from the drop-down list.

7. In the drop-down list that appears, click unbounded.

At this point, the XML Schema diagram should look like Figure 71:

Choosing the Element to Include in a Sample complexType in the Diagram View

This topic is part of a sequence that begins with Description of Sample XML Schema.

In the sample XML Schema, you want PublicationType elements to contain an ISBNnumber, PUBnumber, or LOCnumber element.

To specify this:
1. Right-click the sequence node belonging to the PublicationType node.
2. In the shortcut menu that appears, select Add > Sqeuence.

Stylus Studio displays a representation for the new sequence node in the diagram. Sequence properties appear in the Properties window.

We added the sequence node in error - the specification requires that this node be a choice node. The QuickEdit feature makes it easy to correct errors such as this.

3. Right-click the new sequence node. In the shortcut menu that appears, select QuickEdit > Switch to Choice.

Stylus Studio changes the sequence node to the choice node ( ).

4. Right-click the new choice node.
5. In the shortcut menu that appears, select Add > Element.
6. In the Properties window, change the Name to ISBNnumber and press Enter.
7. In the Properties window, change the Typexsd:int and press Enter.
8. Repeat step 4 through step 7 twice: once to add the PUBnumber element, and once to add the LOCnumber element.
9. Click Save .

The definition of the PublicationType complexType is now complete and should look like Figure 72:

 
Free Stylus Studio XML Training:
W3C Member