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
广告