XML Schema complexType element
Definition and usage
complexType element defines a complex type. A complex type element is an XML element that contains other elements and/or attributes.
Element information
Occurrence count | Unrestricted within the schema; once within an element. |
Parent element | element, redefine, schema |
Content | annotation, simpleContent, complexContent, group, all, choice, sequence, attribute, attributeGroup, anyAttribute |
Syntax
<complexType id=ID name=NCName abstract=true|false mixed=true|false block=(#all|list of (extension|restriction)) final=(#all|list of (extension|restriction)) any attributes > (annotation?,(simpleContent|complexContent|((group|all| choice|sequence)?,((attribute|attributeGroup)*,anyAttribute?)))) </complexType>
(? Symbol declared in the complexType element, the element can appear zero or one time, * Symbol declared element can appear zero or more times.)
Attributes
id
Optional. Specifies the unique ID of the element.
name
Optional. Specifies the name of the element.
abstract
Optional. Specifies whether complex types can be used in the instance document. If the value is true, the element cannot directly use the complex type but must use a complex type derived from it. The default value is false.
mixed
Optional. Specifies whether character data is allowed to appear between child elements of the complex type. The default value is false.
- If the simpleContent element is a child element, the mixed attribute is not allowed.
- If the complexContent element is a child element, the mixed attribute can be overridden by the mixed attribute of the complexContent element.
block
Optional. Prevents complex types with the specified derivation type from being used to replace the complex type. The value can contain #all or a list, which is a subset of extension or restriction:
- extension - Prevents derived complex types through extension from being used to replace the complex type.
- restriction - Prevents derived complex types through restriction from being used to replace the complex type.
- #all - Prevents all derived complex types from being used to replace the complex type.
final
Optional. Prevents the specified type derived from the complexType element from being used. The value can contain #all or a list, which is a subset of extension or restriction.
- extension - Prevents derivation through extension.
- restriction - Prevents derivation through restriction.
- #all - Prevents all derivation (extension and restriction).
any attributes
Optional. Specifies any other attributes with a non-schema namespace.
Instance
Example 1
The following example has a complex type element named "note":
<xs:element name="note"> <xs:complexType> <xs:sequence> <xs:element name="to" type="xs:string"/> <xs:element name="from" type="xs:string"/> <xs:element name="heading" type="xs:string"/> <xs:element name="body" type="xs:string"/> </xs:sequence> </xs:complexType> </xs:element>
Example 2
In the following example, there is a complex type "fullpersoninfo" that extends the inherited type using three additional elements (address, city, and country), derived from another complex type "personinfo":
<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 above example, the "employee" element must contain the following elements in order: "firstname", "lastname", "address", "city", and "country".