XSD - 複雜型別



複雜元素是一種 XML 元素,可以包含其他元素和/或屬性。我們有兩種方式可以建立一個複雜元素 −

  • 定義一個複雜型別,然後使用 type 屬性建立一個元素

  • 透過命名直接定義一個複雜型別

定義一個複雜型別,然後使用型別屬性建立一個元素。

<xs:complexType name = "StudentType">
   <xs:sequence>
      <xs:element name = "firstname" type = "xs:string"/>
      <xs:element name = "lastname" type = "xs:string"/>
      <xs:element name = "nickname" type = "xs:string"/>
      <xs:element name = "marks" type = "xs:positiveInteger"/>
   </xs:sequence>
   <xs:attribute name = 'rollno' type = 'xs:positiveInteger'/>
</xs:complexType>

<xs:element name = 'student' type = 'StudentType' />			 

透過命名直接定義一個複雜型別。

<xs:element name = "student">
   <xs:complexType>   
      <xs:sequence>
         <xs:element name = "firstname" type = "xs:string"/>
         <xs:element name = "lastname" type = "xs:string"/>
         <xs:element name = "nickname" type = "xs:string"/>
         <xs:element name = "marks" type = "xs:positiveInteger"/>
      </xs:sequence>
   <xs:attribute name = 'rollno' type = 'xs:positiveInteger'/>
   </xs:complexType>
<xs:element>

以下是 XSD 支援的複雜型別列表。

序號 簡單型別和描述
1

複雜空複雜型別元素只能有屬性,沒有內容。

2

僅限元素

僅限元素的複雜型別元素只能包含元素

3

僅限文字

僅限文字的複雜型別元素只能包含屬性和文字。

4

混合

混合複雜型別元素可以包含元素、屬性和文字。

5

指示器

指示器控制元素在 XML 文件中組織的方式。

6

<any>

<a&gt;元素用於架構未定義的元素

7

<anyAttribute>

<a>屬性用於架構未定義的屬性。

廣告
© . All rights reserved.