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 this value is true, the element cannot use the complex type directly 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 this 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 specified derivation types from being used in place of this complex type. This value can contain #all or a list, which is a subset of extension or restriction:
- extension - Prevents derived complex types by extension from being used in place of this complex type.
- restriction - Prevents derived complex types by restriction from being used in place of this complex type.
- #all - Prevents all derived complex types from being used in place of this complex type.
final
Optional. Prevents the specified type derived from the complexType element from being used. This value can contain #all or a list, which is a subset of extension or restriction.
- extension - Προστατεύει από παραγώγους μέσω εκτάσεων.
- restriction - Προστατεύει από παραγώγους μέσω περιορισμού.
- #all - Προστατεύει από όλες τις παραγώγους (εκτάσεις και περιορισμούς).
any attributes
Επιλογή. Καθορίζει οποιεσδήποτε άλλες ιδιότητες με non-schema ονομαστικό χώρο.
Παράδειγμα
Παράδειγμα 1
Το παρακάτω παράδειγμα έχει έναν περίπλοκο τύπο στοιχείου με το όνομα "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>
Παράδειγμα 2
Στο παρακάτω παράδειγμα υπάρχει ένας περίπλοκος τύπος "fullpersoninfo" που επεκτείνει τον τύπο που κληρονομείται χρησιμοποιώντας τρεις επιπρόσθετους στοιχεία (address, city και country) και προέρχεται από έναν άλλο περίπλοκο τύπο "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>
Στο παραπάνω παράδειγμα, το στοιχείο "employee" πρέπει να περιέχει σε σειρά τα παρακάτω στοιχεία: "firstname", "lastname", "address", "city" και "country".