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 参考