复杂空元素只能有属性,但没有内容。 请参阅以下示例 -
<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>