XML Schema complexContent Element

Definition and usage

The <complexContent> element defines the extension or restriction of a complex type (including mixed content or only containing elements).

Element information

Occurrence One
Parent element complexType
Content

Optional. annotation

Mandatory. There must be and only one of the following elements: restriction (complexContent) or extension (complexContent).

Syntax

<complexContent
id=ID
mixed=true|false
any attributes
>
(annotation?,(restriction|extension))
</complexContent>

(? The '?' symbol indicates that the element can appear zero or one times within the complexContent element.)

Attribute Description
id Optional. Specifies the unique ID of the element.
mixed Optional. Specifies whether character data is allowed to appear between the child elements of this complexType element. The default value is false.
any attributes Optional. Specifies any other attributes with non-schema namespace.

Example

In the following example, there is a complex type "fullpersoninfo" which is derived from another complex type "personinfo" by extending the inherited type with three additional elements:

<xs:element name="employee" type="fullpersoninfo"/>
<xs:complexType name="personinfo">
  <xs:sequence>
    <xs:element name="firstname" type="xs:string"/>
    <xs:element name="lastname" type="xs:string"/>
  </xs:sequence>
</xs:complexType>
<xs:complexType name="fullpersoninfo">
  <xs:complexContent>
    <xs:extension base="personinfo">
      <xs:sequence>
        <xs:element name="address" type="xs:string"/>
        <xs:element name="city" type="xs:string"/>
        <xs:element name="country" type="xs:string"/>
      </xs:sequence>
    </xs:extension>
  </xs:complexContent>
</xs:complexType>

In the example above, the "employee" element must contain the following elements in order: "firstname", "lastname", "address", "city", and "country".