Creating an XML schema

In this section we shall create an XML schema, catalog.xsd (as listed in the introduction), in JDeveloper Schema Visual Editor. First, add a schema file to project XMLSchema. Select the XMLSchema node in Application Navigator and select File|New. In the New Gallery window select General|XML in Categories, and XML schema in Items. Click on the OK button.

Creating an XML schema

In the Create XML schema window specify a File Name, catalog.xsd, and click on OK. An XML schema gets added to project XMLSchema. In the Design view, the different components of the schema are displayed in the schema visual editor. In the Source view, the schema document source is listed. The different schema components available to add to a schema are listed in the Schema Components Component Palette.

Creating an XML schema

Components may be added to an XML schema either from the Component Palette or a component node in the schema. As an example of adding a component from a component node, add root element catalog. Right-click on<schema> node in Design view, and select Insert inside schema|element.

Creating an XML schema

An element, element1 gets added to the schema element.

Creating an XML schema

Next, we modify the element1 properties such as name and type in the Property Inspector. The Property Inspector may be started either by selecting the Property Inspector tab or by right-clicking on the component node and selecting Go To Properties. The Property Inspector UI in JDeveloper 11g is on the righthand side of the screen by default, but you have the option to drag the Property Inspector window to the bottom where it is easier to read. In the Property Inspector, select the XMLSchema tree and modify the element name to catalog. Specify type as catalogType. Properties abstract, block, default, final, fixed, id, nillable, and substitutionGroup may also be set in the Property Inspector. The detail of these properties may be referred to in the W3C XML Schema Structures (http://www.w3.org/TR/xmlschema-1/#cElement_Declarations).

Creating an XML schema

An element may also be added by selecting in Design view the node to which the element is to be added and selecting element in the Component Palette. A component may also be added from the Component Palette to a Design view component by selecting the component in the Component Palette and dragging the component to the Design view component and dropping it.

Element properties such as element name, element type, and other properties may still be modified in the Property Inspector. To delete the exampleElement element, right-click on the exampleElement node and select Delete. Next, we add complextType catalogType to the <schema> node from the Component Palette. Select the schema component in the Design view and select complexType from the Component Palette.

Creating an XML schema

A complexType gets added to the schema element. Set the complexType name and other properties in the Property Inspector.

Creating an XML schema

A complexType may also be added from the Design view by right-clicking on the schema node and selecting Insert inside schema|complexType. Next, add a sequence element to complexType-catalogType. Right-click on the catalogType node and select Insert inside complexType|sequence.

Creating an XML schema

A sequence node gets added to the catalogType node. The sequence node has a default cardinality of 1. Next, we shall add a journal element to the sequence node. Right-click on the sequence node and select Insert inside sequence|element.

Creating an XML schema

An element node gets added to the sequence node. In the Property Inspector specify element name as journal and type as journalType. Also, set the attribute minOccurs to 0, and maxOccurs to unbounded. The type of the element may also be set by right-clicking on the element and selecting Set Type.

Creating an XML schema

The properties of any of the nodes may be modified by selecting the node in the Design view and setting the properties in the Property Inspector. Next, we add complexType journalType to the schema element. Right-click on the schema element and select Insert inside schema|complexType.

Creating an XML schema

A complexType may also be added from the Component Palette. A complexType node gets added to the schema node. Next, we add an element sequence to journalType node. Set the complexType name to journalType in the Property Inspector. Right-click on the complexType node and select Insert inside complexType|sequence. A sequence may also be added by selecting the journalType node, and selecting sequence in the Component Palette.

Creating an XML schema

A sequence node gets added. Next, we add the article element to the sequence. Right-click on the sequence node and select Insert inside sequence|element. An element may also be added to the sequence from the Component Palette.

Creating an XML schema

An element node gets added to the element sequence. In the Property Inspector, set the element name to article, minOccurs to 0 and maxOccurs to unbounded, and type to articleType.

Creating an XML schema

Next, add the attributes title, publisher, and edition to journalType complexType. To add an attribute, right-click on the journalType node and select Insert inside complexType-journalType|attribute. An attribute may also be added by selecting the journalType node and selecting attribute in the Component Palette.

Creating an XML schema

Set the attribute name to title and type to xsd:string in the Property Inspector.

Creating an XML schema

Similarly, add the attributes publisher and edition to journalType complexType.

Creating an XML schema

Add complexType-articleType to the schema node with the procedure with which catalogType and journalType were added; either from the Component Palette or by right-clicking on the schema node and selecting Insert inside schema|complexType. Set the complexType name to articleType in the Property Inspector. Next, add an element sequence to articleType either from the Component Palette, or by right-clicking on the articleType and selecting Insert inside complexType|sequence. Right-click on the sequence node and select Insert inside sequence|element to add an element node to the sequence node.

An element node may also be added from the Component Palette. In the Property Inspector set the element name to title, and type to xsd:string in the Property Inspector. Similarly, add element author of type xsd:string to the sequence.

Creating an XML schema

ComplexType-articleType also has an attribute section. To add an attribute right-click on the articleType node and select Insert inside complexType|attribute. The section attribute may also be added to articleType from the Component Palette. Set the attribute name to section and type to xsd:string in the Property Inspector. The complete schema document, catalog.xsd, is shown in Design view in the following illustration. Select File|Save to save the XML schema.

Creating an XML schema