Microsoft XML Core Services (MSXML) 5.0 for Microsoft Office - XML Schemas

complexType

Defines a complex type, which determines the set of attributes and the content of an element.

<complexType
  abstract = Boolean : false 
  block = (#all | List of (extension | restriction))
  final = (#all | List of (extension | restriction))
  id = ID 
  mixed = Boolean : false
  name = NCName 
  {any attributes with non-schema Namespace…}>
Content: (annotation?, (simpleContent | complexContent | ((group | all | 
choice | sequence)?, ((attribute | attributeGroup)*, anyAttribute?))))
</complexType>

Attributes

abstract
An indicator of whether the complex type can be used in an instance document. If this value is true, an element cannot use this complex type directly but must use a complex type derived from this complex type. The default is false.

Optional.

block
The type of derivation. The block attribute prevents a complex type that has the specified type of derivation from being used in place of this complex type. This value can contain #all or a list that is a subset of extension or restriction. The block attribute is only used when, during validation, an instance document overrides the normal type for an element by using the schema-instance:type attribute. The block attribute is capable of stopping elements from selecting complex types that are defined through extension and/or restriction to replace the original type that is specified for the element.

extension Prevents complex types derived by extension from being used in place of this complex type.
restriction Prevents complex types derived by restriction from being used in place of this complex type.
#all Prevents all derived complex types from being used in place of this complex type.

Optional.

final
The type of derivation. The final attribute prevents the specified type of derivation of this complexType element. This value can contain #all or a list that is a subset of extension or restriction.

extension Prevents derivation by extension.
restriction Prevents derivation by restriction.
#all Prevents all derivation (both extension and restriction).

Optional.

id
The ID of this element. The id value must be of type ID and be unique within the document containing this element.

Optional.

mixed
An indicator of whether character data is allowed to appear between the child elements of this complex type. The default is false.

If simpleContent element is a child element, the mixed attribute is not allowed.

If complexContent element is a child element, this mixed attribute can be overridden by the mixed attribute on the complexContent element.

Optional.

name
The name of the type. The name must be a no-colon-name (NCName) as defined in the XML Namespaces specification.

Required if the containing element is the schema element; otherwise, prohibited.

If specified, the name must be unique among all simpleType and complexType elements.

Optional.

Element Information

Number of occurrences Unlimited within schema; one time within element.
Parent elements element, redefine, schema
Content annotation, simpleContent, complexContent, group, all, choice, sequence, attribute, attributeGroup, anyAttribute

Remarks

A complex type is essentially a type definition for elements that may contain attributes and elements. An element can be declared with a type attribute that refers to a complexType element that defines the structure, content, and attributes of that element. (An element can also take a reference to a simpleType in its type attribute.)

A complex type can contain one and only one of the following elements, which determines the type of content allowed in the complex type.

Element Description
simpleContent The complex type has character data or a simpleType as content and contains no elements, but may contain attributes.
complexContent The complex type contains only elements or no element content (empty).
group The complex type contains the elements defined in the referenced group.
sequence The complex type contains the elements defined in the specified sequence.
choice The complex type allows one of the elements specified in the choice element.
all The complex type allows any or all of the elements specified in the all element to appear once.

If group, sequence, choice, or all is specified as the child element, the attributes for the complexType can be declared optionally using the following elements.

Element Description
attribute The complex type contains the specified attribute.
attributeGroup The complex type contains the attributes defined in the referenced attributeGroup.
anyAttribute The complex type can contain any attribute from the specified namespace(s).

Any number of attribute or attributeGroup elements can be used. One instance of anyAttribute can also be used.

If group, sequence, choice, or all is specified, the elements must appear in the following order.

  1. group | sequence | choice | all
  2. attribute | attributeGroup
  3. anyAttribute

Examples

The following example shows a complex type that contains a simple type (decimal) with an attribute and element declaration that uses a complex type.

<xs:complexType name='internationalShoeSize'>
 <xs:simpleContent>
  <xs:extension base='xs:decimal'>
   <xs:attribute name='sizing' type='xs:string' />
  </xs:extension>
 </xs:simpleContent>
</xs:complexType>
<xs:element name='myShoeSize' type='internationalShoeSize'/>

The following example shows an instance of the myShoeSize element within an XML document.

<myShoeSize sizing='UK'>10.5</myShoeSize>

The following example shows the myShoeSize element with the complexType defined anonymously within the element. (Note the absence of the name attribute.)

<xs:element name='myShoeSize'>
 <xs:complexType>
  <xs:simpleContent>
   <xs:extension base='xs:decimal'>
     <xs:attribute name='sizing' type='xs:string' />
   </xs:extension>
  </xs:simpleContent>
 </xs:complexType>
</xs:element>

See Also

XML Schema Reference (XSD) | XML Schema Elements

For more information, see the W3C XML Schema Part 1: Structures Recommendation at http://www.w3.org/TR/2001/REC-xmlschema-1-20010502/#element-complexType.

Other Resources Other Resources

W3C Namespaces in XML Recommendation