XML Schema 参考手册 完整 XML Schema 参考手册 The complexType element defines a complex type. Elements of complex types are XML elements that contain other elements and / or attributes. 父元素: Element, redefine, schema (? Symbol declaration in the complexType element, the element can appear zero or once, and the* symbol declares that the element can appear zero or more times. ) Attribute Description 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 use the complex type directly, but must use the complex type derived from the complex type. The default is false. Mixed Optional. Specifies whether character data is allowed to appear between child elements of this complex type. The default 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 a complex type with a specified derived type from being used to replace that complex type. The value can contain # all or a list that is a subset of extension or restriction: Extension-prevents a complex type derived from an extension from being used to replace that complex type. Restriction-prevents a complex type derived by restriction from being used to replace that complex type. # all-prevents all derived complex types from being used to replace that complex type. Final Optional. Prevents the specified type from being derived from this complexType element. The 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 derivations (extensions and restrictions). Any attributes Optional. Specifies any other attributes with the non-schema namespace. The following example has a complex type element named “note”: In the following example, there is a complex type “fullpersoninfo” that extends the inherited type by using three supplementary elements (address, city, and country), derived from another complex type “personinfo”: In the above example, the “employee” element above must contain the following elements in order: “firstname”, “lastname”, “address”, “city”, and “country”.Definition and usage ¶
Element information ¶
Grammar ¶
<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>
Example 1 ¶
<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 ¶
<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>