当前位置:K88软件开发文章中心编程语言XmlSchema01 → 文章内容

XML Schema 复合空元素

减小字体 增大字体 作者:佚名  来源:网上搜集  发布时间:2019-1-13 11:10:43

XSD 空元素空的复合元素不能包含内容,只能含有属性。复合空元素:一个空的 XML 元素:<product prodid="1345" />上面的 "product" 元素根本没有内容。为了定义无内容的类型,我们就必须声明一个在其内容中只能包含元素的类型,但是实际上我们并不会声明任何元素,比如这样:<xs:element name="product">?<xs:complexType>???<xs:complexContent>?????<xs:restriction base="xs:integer">???????<xs:attribute name="prodid" type="xs:positiveInteger"/>?????</xs:restriction>???</xs:complexContent>?</xs:complexType></xs:element>在上面的例子中,我们定义了一个带有复合内容的复合类型。complexContent 元素给出的信号是,我们打算限定或者拓展某个复合类型的内容模型,而 integer 限定则声明了一个属性但不会引入任何的元素内容。但是,也可以更加紧凑地声明此 "product" 元素:<xs:element name="product">?<xs:complexType>???<xs:attribute name="prodid" type="xs:positiveInteger"/>?</xs:complexType></xs:element>或者您可以为一个 complexType 元素起一个名字,然后为 "product" 元素设置一个 type 属性并引用这个 complexType 名称(通过使用此方法,若干个元素均可引用相同的复合类型):<xs:element name="product" type="prodtype"/><xs:complexType name="prodtype">?<xs:attribute name="prodid" type="xs:positiveInteger"/></xs:complexType>

XML Schema 复合空元素