XSD - 複雜空元素



複雜空元素只能有屬性,沒有內容。請參閱以下示例 −

<student rollno = "393" />

我們可以使用以下方法聲明覆雜空元素 −

使用 type 屬性

聲明覆雜型別元素“StudentType”,然後建立型別為 “StudentType”的元素 student。

<xs:complexType name = "StudentType">
   <xs:attribute name = 'rollno' type = 'xs:positiveInteger'/>   
</xs:complexType>

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

使用 ComplexContent

使用 complexContent 定義 complexType 的元素。ComplexContent 指定要限制該元素的內容。

<xs:element name = "student">
   <xs:complexType>
      <xs:complexContent>
         <xs:restriction base = "xs:integer">
            <xs:attribute name = "rollno" type = "xs:positiveInteger"/>
         </xs:restriction>
      </xs:complexContent>
   </xs:complexType>
</xs:element>		 

僅使用 ComplexType

僅使用 required 屬性元素定義 complexType 的元素。

<xs:element name = "student">
   <xs:complexType>
      <xs:attribute name = "rollno" type = "xs:positiveInteger"/>
   </xs:complexType>
</xs:element>
xsd_complex_types.htm
廣告
© . All rights reserved.