xs:complexType

Purpose

This element enables you to define a content model for a complex data type.

You can use three compositors for different ways of combining data:

Furthermore, it offers the possibility to define simple content models (xs:simpleContent), attributes (xs:attribute) and wildcards for attributes (xs:anyAttribute).

Parent element xs:element or xs:schema
Child elements xs:all, xs:anyAttribute, xs:attribute, xs:attributeGroup, xs:choice, xs:complexContent, xs:group, xs:sequence, xs:simpleContent
Attributes abstract, block, final, mixed, name
Attributes
Name Type Description
abstract xs:boolean If "true", the complex type definition must not be used for validation, i.e. an instance must reference, for example, a derived type via xsi:type. Default: "false".
block  

This attribute, in conjunction with the xs:schema element's blockDefault attribute (if the block attribute is not specified, the blockDefault attribute value takes effect), is used at validation time. It specifies the types that may be used in an xsi:type attribute of an element that is validated against an element declaration that references this complex type definition. The value is a whitespace-separated list of:

extension

The type referenced by xsi:type must not be derived from the current type by extension.

restriction

The type referenced by xsi:type must not be derived from the current type by restriction.

Alternatively, the special value "#all" indicates that no xsi:type may be used.

final  

This attribute, in conjunction with the xs:schema element's finalDefault attribute (if the final attribute is not specified, the finalDefault attribute value takes effect), is used when performing schema checks. It specifies the methods that may be used to derive new types from the current complex type. The value is a whitespace-separated list of:

extension

No type may be derived from this complex type by extension.

restriction

No type may be derived from this complex type by restriction.

Alternatively, the special value "#all" prevents both methods of deriving a new type from the current complex type definition.

mixed xs:boolean Specifies whether the complex type being defined with the xs:complexType element allows mixed content (i.e. a combination of text and child elements). The default value for the mixed attribute is false, indicating that mixed content is not allowed.
name xs:NCName

For purposes of reuse, it is possible to specify a name attribute for a complex type definition if xs:complexType is used in the context of xs:schema, and to reference it later by this name. This is done with the name attribute of the xs:complexType element.

This attribute is mandatory for the definition of named complex types. For anonymous complex types it must be omitted.

Note:
Versions of Tamino up to Tamino 3.1 only supported anonymous complex type definitions.

Examples

This example of a complex type definition is taken from the "Jazz" schema example as introduced in the Advanced Concepts documentation. It uses xs:all to define a structure containing the two elements location and time:

<xs:complexType>
  <xs:all>
    <xs:element name = "location"
                type = "xs:normalizedString"/>
    <xs:element name = "time" type = "xs:dateTime"/>
  </xs:all>
</xs:complexType>

The next example is based on the previous one and adds a sequence to it:

<xs:complexType>
  <xs:choice>
    <xs:sequence>
      <xs:element name = "from" type = "xs:date"/>
      <xs:element name = "to" type = "xs:date"/>
    </xs:sequence>
    <xs:all>
      <xs:element name = "location"
                  type = "xs:normalizedString"/>
      <xs:element name = "time" type = "xs:dateTime"/>
    </xs:all>
  </xs:choice>
</xs:complexType>

The next example shows the definition of an element named collaborationContext using a choice that includes xs:sequence and xs:all.

<xs:element name = "collaborationContext">
  <xs:complexType>
    <xs:choice>
      <xs:sequence>
        <xs:element name = "from" type = "xs:date"/>
        <xs:element name = "to" type = "xs:date"/>
      </xs:sequence>
      <xs:all>
        <xs:element name = "location"
                    type = "xs:normalizedString"/>
        <xs:element name = "time" type = "xs:dateTime"/>
      </xs:all>
    </xs:choice>
  </xs:complexType>
</xs:element>