XML Schema complexType 元素
定義和用法
complexType 元素定義復(fù)雜類型。復(fù)雜類型的元素是包含其他元素和/或?qū)傩缘?XML 元素。
元素信息
出現(xiàn)次數(shù) | 在架構(gòu)內(nèi)為無限制;在元素內(nèi)為一次。 |
父元素 | element、redefine、schema |
內(nèi)容 | annotation、simpleContent、complexContent、group、all、choice、sequence、attribute、attributeGroup、anyAttribute |
語法
<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>
(? 符號(hào)聲明在 complexType 元素中,元素可出現(xiàn)零次或一次,* 符號(hào)聲明元素可出現(xiàn)零次或多次。)
屬性
id
可選。規(guī)定該元素的唯一的 ID。
name
可選。規(guī)定元素的名稱。
abstract
可選。規(guī)定在實(shí)例文檔中是否可以使用復(fù)雜類型。如果該值為 true,則元素不能直接使用該復(fù)雜類型,而是必須使用從該復(fù)雜類型派生的復(fù)雜類型。 默認(rèn)值為 false。
mixed
可選。規(guī)定是否允許字符數(shù)據(jù)出現(xiàn)在該復(fù)雜類型的子元素之間。 默認(rèn)值為 false。
- 如果 simpleContent 元素是子元素,則不允許 mixed 屬性。
- 如果 complexContent 元素是子元素,則該 mixed 屬性可被 complexContent 元素的 mixed 屬性重寫。
block
可選。防止具有指定派生類型的復(fù)雜類型被用來替代該復(fù)雜類型。該值可以包含 #all 或者一個(gè)列表,該列表是 extension 或 restriction 的子集:
- extension - 防止通過擴(kuò)展派生的復(fù)雜類型被用來替代該復(fù)雜類型。
- restriction - 防止通過限制派生的復(fù)雜類型被用來替代該復(fù)雜類型。
- #all - 防止所有派生的復(fù)雜類型被用來替代該復(fù)雜類型。
final
可選。防止從該 complexType 元素派生指定的類型。該值可以包含 #all 或者一個(gè)列表,該列表是 extension 或 restriction 的子集。
- extension - 防止通過擴(kuò)展派生。
- restriction - 防止通過限制派生。
- #all - 防止所有派生(擴(kuò)展和限制)。
any attributes
可選。規(guī)定帶有 non-schema 命名空間的任何其他屬性。
實(shí)例
例子 1
下面的例子擁有一個(gè)名為 "note" 的復(fù)雜類型元素:
<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
下面的例子中有一個(gè)復(fù)雜類型 "fullpersoninfo",它通過使用三個(gè)補(bǔ)充的元素 (address、city 和 country) 對(duì)繼承的類型進(jìn)行擴(kuò)展,由另一個(gè)復(fù)雜類型 "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"。