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>

原文来自:https://www.runoob.com/schema/schema-complex-empty.html

本文地址:https://www.linuxprobe.com/xsd-null-elements.html编辑:王艳敏,审核员:逄增宝

Linux命令大全:https://www.linuxcool.com/

Linux系统大全:https://www.linuxdown.com/

红帽认证RHCE考试心得:https://www.rhce.net/

© 版权声明
THE END
喜欢就支持一下吧