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.

Figure 83. The XMLSchema Editor Diagram Tab

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.

Figure 84. New complexType

4. Type PublicationType in the Name property in the Properties window and press Enter.

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).

Figure 85. Adding an Attribute in the Diagram Tab

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 86

Figure 86. The Finished genre Attribute
.

Tip

 

You can toggle the display of attributes by clicking the small triangle at the bottom of the complexType node.

6. Click Save .

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 87:

Figure 87. PublicationType complexType

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 > Complex Type 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.

Tip

 

A plus sign appears on the right side of the author element. You can click the plus sign to display the definition of the AuthorType complexType, which was just added to the author element.

6. Click the Max Occur. field.
7. In the drop-down list that appears, click unbounded.

Tip

 

When you give an element an unbounded maximum number of occurrences, Stylus Studio renders the node using two outlines, to indicate that multiple occurrences of this element are allowed.

8. Click Save .

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

Figure 88. author Element with AuthorType complexType

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 Type xsd: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 89:

Figure 89. PublicationType complexType Fully Defined

 
Free Stylus Studio XML Training: