Latest web development tutorials

XML Schema complexContent 元素

XML Schema 參考手冊 完整XML Schema參考手冊

定義和用法

complexContent 元素定義對複雜類型(包含混合內容或僅包含元素)的擴展或限制。

元素信息

  • 父元素: complexType

語法

<complexContent
id=ID
mixed=true|false
any attributes

>

(annotation?,(restriction|extension))

</complexContent>

(? 符號聲明元素可在complexContent 元素內出現零次或一次。)

属性 描述
id 可选。规定该元素的唯一的 ID。
mixed 可选。规定是否允许字符数据出现在该 complexType 元素的子元素之间。 默认值为 false。
any attributes 可选。规定带有 non-schema 命名空间的任何其他属性。

實例1

下面的例子中有一個複雜類型"fullpersoninfo",這個複雜類型是通過用三個補充的元素擴展繼承的類型,從另一個複雜類型"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 參考手冊 完整XML Schema參考手冊