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

XML Schema 复合空元素

减小字体 增大字体 作者:佚名  来源:网上搜集  发布时间:2019-1-26 18:49:41

由 chenlei5720 创建,Carrie 最后一次修改 2015-09-29 XSD 空元素 有关 XML Schema 复合空元素的知识,本节将为你描述。 空的复合元素不能包含内容,只能含有属性。 复合空元素: 一个空的 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 复合空元素