Skip Headers
Oracle® Application Server Integration InterConnect User's Guide
10g Release 2 (10.1.2)
B14069-02
  Go To Documentation Library
Home
Go To Product List
Solution Area
Go To Table Of Contents
Contents
Go To Index
Index

Previous
Previous
Next
Next
 

10 XML Schema Definition

This chapter provides an overview of XML Schema Definition (XSD) and describes how InterConnect supports XSD. It contains the following topics:

Overview of XSD

An XSD defines the structure of an XML document. It specifies the elements and attributes that can appear in an XML document and the type of data these elements and attributes can contain. This information is used to verify that each element or attribute in an XML document adheres to its description.

Advantages of XSD over DTD

Following are the advantages of XSD over Document Type Definition (DTD):

  • XSD is extensible. You can derive new elements from the existing elements. DTD is not extensible.

  • XSD is defined in XML. It does not require intermediate processing by a parser. DTD is not defined in XML. You need separate parsers for DTD and XML.

  • XSD supports data types. You can restrict the content of an element. DTD does not support data types. Therefore, you cannot restrict the content of an element.

  • XSD supports default values. You can specify default values of the elements. You cannot specify the default values of elements in DTD.

  • XSD supports references to external XML schemas. You can include or import more than one XML schema within an XML schema. You cannot include other DTDs within a DTD.

XSD Elements and Attributes

An XML schema defines elements and their structures. It also defines the attributes and their data types. The elements' structures can be of simpleType or complexType, depending on whether the element is a leaf element or a parent element.


See Also:

"XSD Type Definitions" for more information on simpleType and complexType

XSD Elements

XSD elements can be of type simpleType, complexType, or anyType. An element of type simpleType contains only text. It cannot have attributes and elements. An element of type complexType can contain text, elements, and attributes. An element of type complexType is parent to all the elements and attributes contained within it. An any element in an XSD specifies that any well-formed XML is allowed in its place in XML instance.

InterConnect stores the type simpleType as a member of the object created for the parent element. The data type of this member is the InterConnect data type corresponding to the XSD data type. For example, Address1 is a complexType that contains two simpleType elements, City and State. myAddress is an element of Address1 complexType. InterConnect stores Address1 as an object, and City and State as InterConnect data type String. myaddress is stored as InterConnect data type Reference that contains reference to object of complexType, Address1. InterConnect stores the name of any element in the _any_ format. At run time, InterConnect treats an any element as string.

Elements can be local or global. An elements declared as the direct child of an XML schema is called a global element and can be used throughout the schema. Elements declared within a complex type definition are local elements. So, you cannot use these elements anywhere else in the schema. When you import an XSD, InterConnect displays all the global elements of this XML schema as well as all the imported or included XML schemas. These global elements are grouped together based on their namespaces. You can browse through the namespaces and select a global element. This global element acts as root of the message when defining an application view or common view. It also acts as root of the type generated when defining application data types or common data types.

When you select an element as the root element, all the elements starting from the structure of the selected element untill the end are stored in the repository. An element can have constraints such as minOccurs and maxOccurs. If the value of the maxOccurs constraint of an element is greater than one, then the element is stored as an array.

XSD Attributes

XSD attributes are always of type simpleType. The syntax for defining an attribute is:

<xs:attribute name="myattribute" type="string"/>

In this example, myattribute is an attribute of data type string. An attribute can have a fixed or default value. InterConnect stores the fixed or default value of an attribute. Attributes are stored as member of the object created for the parent element. The data type of this attribute is the InterConnect data type corresponding to the XSD base data type.

An attribute group defines an association between a name and a set of attribute declarations. You can reuse the attribute groups in complexType definitions. The syntax for defining an attribute group is:

<xsd:attributeGroup name="Address">
<xsd:attribute name="Street1" type="xs:string"/>
<xsd:attribute name="Street2" type="xs:string"/>
<xsd:attribute name="City" type="xs:string"/>
<xsd:attribute name="State" type="xs:string"/>
</xsd:attributeGroup>

In this example, Address is the name of the attribute group that contains attributes such as Street1, Street2, City, and State. InterConnect resolves the attribute group references by copying the attributes definition to the referencing complexType.

anyAttribute

Like the any element, anyAttribute specifies that any attribute can be used in its place in the XML instance. InterConnect stores anyAttribute as an attribute with its name in the format _anyAttribute_. The type of this attribute is stored as String.

Nillable

Sometimes, you need to represent unknown information, or inapplicable information, explicitly with an element. For example, you might need to represent a null value being sent to or from a relational database with an element. In such cases, you can declare the nillable attribute of an element as true in its XML schema definition. InterConnect stores the nillable attribute value in the repository while importing the XSD.

XSD Type Definitions

XSD Type definitions are used to create new simpleType data type or complexType data type. A type definition that is used as a base for creating new definitions is known as the base type definition. A simpleType or complexType type can be either named or anonymous. A named simpleType or complexType is always defined globally. You can define a named simpleType or complexType and refer it in schema document as type of an element. An anonymous simpleType or complexType type does not have a name. So, an anonymous simpleType or complexType type cannot be referenced.

simpleType

XML schema has several built-in data types. A simpleType type is derived from an XML schema built-in data type. For example, to create a new simpleType type called myInt that has range of values between 10000 and 99999, you can base the definition of myInt on the built-in data type Integer.

Each XML schema built-in data type is mapped to an InterConnect data type. When you import an XSD that has an element of type simpleType, InterConnect identifies to which InterConnect data type this element should be mapped. InterConnect also stores the original XSD data type of an element. For example, if you import an XSD that contains an element of XSD data type dateTime, then it will be stored as InterConnect data type Date. In addition, InterConnect also stores the dateTime data type, which is the XSD data type of the element, and its format in the repository. This pattern is used at run time for converting the Date object to date strings.

Table 10-1 shows how various XSD data types are mapped to InterConnect data types in InterConnect.

Table 10-1 Mapping Between XSD Data Types and InterConnect Data Types

XSD Data Type InterConnect Data Type

xsd:integer, xsd:nonPositiveInteger, xsd:negativeInteger, xsd:long, xsd:int, xsd:short, xsd:byte, xsd:nonNegativeInteger, xsd:unsignedLong, xsd:unsignedInt, xsd:unsignedShort, xsd:unsignedByte, xsd:positiveInteger

Integer

xsd:double, xsd:decimal

Double

xsd:float

Float

xsd:string, xsd:normalizedString, xsd:token, xsd:language, xsd:NMTOKEN, xsd:Name, xsd:NCName, xsd:ID, xsd:IDREF, xsd:ENTITY, xsd:anyURI, xsd:QName, xsd:NOTATION, xsd:NMTOKENS, xsd:IDREFS, xsd:ENTITIES, xsd:duration, xsd:time, xsd:gYearMonth, xsd:gYear, xsd:gMonthDay, xsd:gDay, xsd:gMonth

String

xsd:binary and xsd:base64binary

Binary

xsd:date, xsd:datetime

Date

xsd:boolean

Boolean


complexType

A complexType type definition contains a set of element declarations, element references, and attribute declarations.You first define a complexType type in schema and then, you define the elements and attributes of this complexType type.

InterConnect stores a complexType type as an object. A complexType type can be either named or anonymous. When an imported XML schema has anonymous complexType type, then InterConnect generates its object name based on the name of the element. The type of this object is anonymous complexType. For example, when you import an XSD that contains an element MyElement of type anonymous complexType, InterConnect generates and stores the object for the element with a typename such as MyElement_CT.

anyType

All the complexTypes and simpleTypes data types are derived from anyType. So, anyType is the base type of all simpleTypes and complexTypes data types. You can create an element of type anyType by not specifying its data type in the definition. You cannot restrict the content of an anyType element. When you import an XSD that contains an element of type anyType, then InterConnect stores this anyType as String. An element of type anyType can be mapped only to an element of type anyType while doing transformations.

anySimpleType

All the simpleTypes data types of XML schema are derived from anySimpleType. So, anySimpleType is the base type of all simpleTypes data types. While importing an XSD, if an attribute does not have its type defined, then InterConnect treats the attribute type as anySimpleType. At run time, an anySimpleType element is treated as String. An anySimpleType element is mapped only to an element or attribute of type anySimpleType during transformation.

XSD Content Models

You can define and name a group of elements in XSD. You can use XSD content models to define the order of elements in a group. When you import a content model, InterConnect automatically detects and resolves the redundancy of the model groups. For example, if a sequence model group with maxOccurs=1 directly contains another sequence model group with maxOccurs=1, then InterConnect automatically detects that the second model group is redundant.

Choice Group

The choice group describes a choice between several possible elements of group. The choice group specifies that only one element can appear in an XML instance. For example, Address1 is a complexType data type that contains two elements, OfficeAddress and ResidenceAddress. You can create a choice group if you want either OfficeAddress or ResidenceAddress to appear in the XML document.

A choice group can contain other groups as well as elements. InterConnect creates an element for a choice group. This element contains all the members of the choice group and is stored as an object in InterConnect having the name _Choice_. If the value of maxOccurs for a choice group is greater than one, then the object of this choice group is created as an array in InterConnect.

Sequence Group

The sequence group specifies that all the elements defined in this group must appear once in the XML document. These elements must appear in a specific order. For example, Address1 is a complexType type that contains two elements OfficeAddress and ResidenceAddress. You can create a sequence group if you want OfficeAddress to appear before ResidenceAddress in XML document.

A sequence group can contain other groups as well as elements. InterConnect creates an element for a sequence group. This element contains all the members of the sequence group and is stored as as object with its name in the format _Sequence_. If the value of maxOccurs for a sequence group is greater than one, then the object of this sequence group is created as an array in InterConnect.

All group

The All group specifies that all the elements defined in this group must appear once in the XML document. These elements can appear in any order in the XML document.

The All group cannot contain other groups. InterConnect creates a element for the All group. This element contains all the members of the All group and is stored as an object in InterConnect having the name _All_. If the value of maxOccurs is greater than one, then the object of this All group is created as an array in InterConnect.

XSD Namespace

XSD namespace is a collection of element and attribute names and their types. The namespace is identified by a unique name, which is a Uniform Resource Identifier (URI). Namespaces are associated with a prefix when they are declared, and this prefix is used along with a local name to represent an element in an XML document. For example, Book:Title where Book is the namespace prefix and Title is name of the element. XSD namespace provides a way to distinguish between duplicate elements, attribute names and their types. When you import an XSD, InterConnect displays all elements grouped by namespace names.

Target namespace defined in a schema specifies the namespace where all the global elements and attributes defined in schema reside. When an element in XSD does not have a named namespace, it means that this element belongs to the NoNamespace namespace.

Include and Import Schema

You can divide an XSD into parts so that it is easier to maintain and read. You can use the xsd:include and xsd:import statements to use the content of one XSD file in another. The include statement is for schemas that exist in the same target namespace or do not have a defined target namespace. The import statement is for schemas that exist in another target namespace. When you import an XSD, InterConnect automatically takes care of all the included or imported XSDs. InterConnect first resolves the schema that is being imported. All references to the types and elements of the schema being imported or included are replaced by their definitions.

InterConnect Validation

InterConnect stores the selected XSD and all included and imported XSD as Binary Large Objects (BLOB) in the InterConnect repository. This is done to validate XML instances against the actual XSDs at run time. Following are the three points at which a message is validated during its flow in InterConnect:

  1. When InterConnect receives a message from an application:

    This validation is performed against the publishing application view XSD. Figure 10-1 displays the Validate XML option as selected. This indicates that the XML instance will be validated against application view XSD.

    Figure 10-1 Enabling Validation for an Application View

    Description of Figure 10-1  follows
    Description of "Figure 10-1 Enabling Validation for an Application View"

  2. After InterConnect transforms a message from application view to common view:

    This validation is performed against the common view XSD. Figure 10-2 displays the Validate XML option as selected. This indicates that the XMl instance will be validated against common view XSD.

    Figure 10-2 Enabling Validation for a Common View

    Description of Figure 10-2  follows
    Description of "Figure 10-2 Enabling Validation for a Common View"

  3. After InterConnect transforms a message from common view to application view: This validation is performed against the subscribing application view XSD.


Note:

XML instances are validated against the actual XSDs only when you select the validate option. You can activate or turn off these points of validation during design time in iStudio.

XSD Type Derivations

You can derive new complexTypes data types by extending or restricting existing simpleTypes or complexType data types. When you import an XSD, InterConnect creates elements for the base and derived types.

Deriving complexTypes by Extension

Extension means taking an existing type as the base and creating a new type by adding to its content. Definition of the base complexType data type is included in the definition of new complexType data type.You can add new elements and attributes to new complexType data type. For example, complexType Employee contains two simpleType elements: FirstName and LastName. You can use complexType Employee to create two new complexTypes, Permanent and Contract. In addition to the FirstName and LastName elements, Permanent complexType can contain elements such as EmpID and DateOfJoining, whereas Contract complexType can contain elements such as ContractStartDate and ContractEndDate.

When you import an XSD in InterConnect, the schema parser parses the schema and gives the resolved schema model. The resolved schema model resolves the type definitions by copying the definition of derived types to deriving type and adding the new elements and attributes to it.

Deriving complexTypes by Restriction

You can derive a complexType data type by restricting a base complexType data type. Restriction is type definition whose declarations are in a one-to-one relation with another specified type definition.

A complexType type derived by restriction is very similar to its base type, except that its declarations are more restricted than the corresponding declarations in the base type. All the components of the base type that are to be included in the derived type must be repeated in the derived type definition. For example complexType Employee contains eight simpleType elements: EmployeeID, FirstName , LastName, DateOfBirth, DateOfJoining, DepartmentNumber, DepartmentName, and DepartmentLocation. You can derive a new ComplexType EmpDept that contains department-related information of an employee such as EmployeeID, DepartmentNumber, DepartmentName, and DepartmentLocation.

When you derive a new type by restriction, the definition of derived types is not copied to the deriving type. InterConnect stores the definition which is being used by the elements in the hierarchy of the selected root element.

Unsupported Features and Limitations of XSD

There are certain features or constructs that are not supported by OracleAS Integration InterConnect. Also, certain features of XSD have some limitations. This section describes the following topics:

Unsupported Features

Following are the unsupported features or constructs in XSD:

  • Mixed Content Types

    If you try to import an XSD having mixed content types, then the InterConnect iStudio throws an error.

  • Support for xsi:type in XML Instance

    In an XML instance, if you specify the xsi:type attribute, then the derived types by extension or restriction appear at the locations where the base type element is expected. InterConnet does not support the xsi:type attribute and assumes that the element is of the original type.

  • The any element

    In a model group definition, if an any element is not located at the end of a sequence, then InterConnect throws an error.

Limitations of XSD

Any ComplexType element having only one single element, which is an any element, is assumed as a String by InterConnect. An element and an attribute contained in the an element cannot have the same name.

XSD validation (the Validate XML option) cannot be used if the payload has a complex structure( XSD based field with additional fields).