The complexContent Element
The preceding example actually took a shortcut with the schema
language. One of the early fullName element declarations used the
xs:simpleContent element to
indicate that the element could only contain simple content (no
nested elements). There is a corresponding content-declaration
element that specifies that a complex type can only contain complex
content (elements). This is the xs:complexContent element.
When the phone element was
declared using an xs:complexType
element with no nested element declarations, the schema processor
automatically inferred that it should contain only complex content.
The phone element declaration
could be rewritten like so, using the xs:complexContent element:
<xs:element name="phone" minOccurs="0">
<xs:complexType>
<xs:complexContent>
<xs:restriction base="xs:anyType">
<xs:attribute name="number" type="xs:string"/>
</xs:restriction>
</xs:complexContent>
</xs:complexType>
</xs:element>The most common reason to use the xs:complexContent element is to derive a
complex type from an existing type. This example derives a new type
by restriction from the built-in xs:anyType type. xs:anyType is the root of all of the
built-in schema types and represents an unrestricted sequence of
characters and markup. Since the xs:complexType indicates that the element
can only contain element content, the effect of this restriction is
to prevent the element from containing either character data or
markup.