XSD复杂类型-空元素

复杂空元素只能有属性,但没有内容。 请参阅以下示例 -

<student rollno = "2019" />

可以使用以下方法声明复杂空元素 -

1. 使用type属性

定义复杂类型元素StudentType,然后创建StudentType类型的元素<student>

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

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

2. 使用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>

3. 仅使用ComplexType
仅使用required元素定义complexType元素。

<xs:element name = "student">
   <xs:complexType>
      <xs:attribute name = "rollno" type = "xs:positiveInteger"/>
   </xs:complexType>
</xs:element>

上一篇: XSD复杂类型 下一篇: XSD字符串