XML Schema Reference

Folder Left Edge Island Home Folder Right Edge
Folder Left Edge Components Online Reference Folder Right Edge
Folder Left Edge Text Page Complete Reference Folder Right Edge
Folder Left Edge Text Page W3C Recs Folder Right Edge
Folder Left Edge Examples Examples Folder Right Edge
Folder Left Edge ? Consulting & Training Folder Right Edge

The complexType Element

A complex type constrains the structure of an element in an XML instance. A complexType element is the XML representation of a complex type. Complex types provide the following functionality:
  • The complex type supports adding attribute types to simple types.
  • The complex type supports "empty content". Empty content means that a corresponding XML instance has no text or embedded elements. A complex type that specifies empty content may have attributes.
  • The complex type supports nested element types.
  • The complex type supports "mixed content". Mixed content means that a corresponding XML instance may contain text interspersed with elements.

Adding an Attribute to a simple type:

    <xsd:complexType name="price"
                     final="restriction"
                     block="restriction"
                     abstract="true"
                     id="price.cType">
        <xsd:annotation>
            <xsd:documentation xml:lang="en">
                Currently, currency is limited to
                U S Dollars. Note that this type defined
                non-instantiable.  A derived type must be
                defined that sets the range.
            </xsd:documentation>
        </xsd:annotation>
        <xsd:simpleContent>
            <xsd:extension base="xsd:decimal">
                <xsd:attribute name="currency"
                               type="xsd:token"
                               fixed="U S Dollars">
                    <xsd:annotation>
                        <xsd:documentation xml:lang="en">
                            U S Dollars are the only currency
                            currently allowed.
                        </xsd:documentation>
                    </xsd:annotation>
                </xsd:attribute>
            </xsd:extension>
        </xsd:simpleContent>
    </xsd:complexType>

Empty Content with one Attribute:

    <xsd:element name="customer">
        <xsd:complexType>
            <xsd:attribute name="customerID"
                           type="xsd:string"
                           use="required"/>
        </xsd:complexType>
    </xsd:element>

Nested Element Types:

    <xsd:complexType name="addressType">
        <xsd:sequence>
            <xsd:element name="address" type="xsd:token"/>
            <xsd:element name="city" type="xsd:token"/>
            <xsd:element name="state" type="xsd:token"/>
            <xsd:element name="country" type="xsd:token" fixed="USA"/>
            <xsd:element name="zip" type="xsd:token"/>
        </xsd:sequence>
    </xsd:complexType>

Mixed Content:

    <xsd:complexType name="catalogEntryDescriptionType"
                     mixed="true"
                     id="catalogEntryDescriptionType.catalog.cType">
        <xsd:annotation>
            <xsd:documentation xml:lang="en">
                Allow the description of a part
                to include part number references.
                The "catalogEntryDescriptionType"
                is a good example of a complex type
                with "mixed" content.
                    -- Shorthand Notation --
            </xsd:documentation>
        </xsd:annotation>
        <xsd:sequence minOccurs="0" maxOccurs="unbounded">
            <xsd:element name="partList" type="partNumberListType"/>
        </xsd:sequence>
    </xsd:complexType>