复杂纯文本元素只能包含文本和属性,但不能包含内容。 请参阅以下示例 -
<marks grade = "A">98</student>
我们可以使用以下方法声明XSD复杂类型-纯文本元素 -
1. 使用SimpleContent
使用simpleContent
定义complexType
。 SimpleContent
可以使用扩展/限制元素来增加/减少元素的基本类型的范围。 使用type
属性创建定义complexType
元素。如下所示 -
<xs:element name = "marks" type = "marksType"/>
<xs:complexType name = "marksType">
<xs:simpleContent>
<xs:extension base = "xs:integer">
<xs:attribute name = "grade" type = "xs:string" />
</xs:extension>
</xs:simpleContent>
</xs:complexType>
2. 仅使用ComplexType
仅使用required
属性定义complexType
元素。
<xs:element name = "marks">
<xs:complexType>
<xs:simpleContent>
<xs:extension base = "xs:integer">
<xs:attribute name = "grade" type = "xs:string" />
</xs:extension>
</xs:complexContent>
</xs:complexType>
</xs:element>