XML Schema complexType 元素
❮ 完整的 XML Schema 參考
定義和用法
complexType 元素定義了一個複雜型別。複雜型別元素是一個包含其他元素和/或屬性的 XML 元素。
元素資訊
- 父元素: element, redefine, schema
語法
<complexType
id=ID
name=NCName
abstract=true|false
mixed=true|false
block=(#all|list of (extension|restriction))
final=(#all|list of (extension|restriction))
任何屬性
>
(annotation?,(simpleContent|complexContent|((group|all|
choice|sequence)?,((attribute|attributeGroup)*,anyAttribute?))))
</complexType>
(? 符號表示元素可以出現零次或一次,* 符號表示元素在 complexType 元素內可以出現零次或多次)
Attribute | 描述 |
---|---|
id | 可選。指定元素的唯一 ID |
name | 可選。為元素指定名稱 |
abstract | 可選。指定是否可以在例項文件中使用此複雜型別。True 表示元素不能直接使用此複雜型別,但必須使用從此複雜型別派生的複雜型別。預設值為 false |
混合 | 可選。指定是否允許字元資料出現在此 complexType 元素的子元素之間。預設值為 false。如果 simpleContent 元素是子元素,則不允許使用 mixed 屬性! |
block | 可選。阻止使用指定型別派生的複雜型別來代替此複雜型別。此值可以包含 #all 或 extension 或 restriction 的子集列表
|
final | 可選。阻止此複雜型別元素的指定型別的派生。可以包含 #all 或 extension 或 restriction 的子集列表。
|
任何屬性 | 可選。指定任何其他非 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”。
❮ 完整的 XML Schema 參考