XSD複雜型別-混合元素

2019-10-16 23:17:56

複雜混合元素可以包含文字,屬性和元素。 請參閱以下範例 -

<student rollno = "10010">
   Dear <firstname>Susen</firstname>    
   <lastname>Su</lastname>
   <nickname>Susen</nickname>
   <marks>95</marks>     
</student>

我們可以使用以下方式宣告這樣的複雜文字 -

1. 使用mixed = true
將屬性mixed設定為true來定義complexTypemixed屬性允許在元素之間包含字元資料。如下所示 -

<xs:complexType name = "StudentType" mixed = "true">
   <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' />

2. 僅使用ComplexType
僅使用required屬性來定義complexType元素。如下所示 -

<xs:element name = 'student'>
   <xs:complexType mixed = "true">
      <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:string"/>
      </xs:sequence>
      <xs:attribute name = 'rollno' type = 'xs:positiveInteger'/>
   </xs:complexType>              
</xs:element>