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 參考手冊