XSD 仅含文本概述

导读 仅含文本的复合元素可包含文本和属性。

XSD 仅含文本概述

仅含文本的复合元素

此类型仅包含简易的内容(文本和属性),因此我们要向此内容添加 simpleContent 元素。当使用简易内容时,我们就必须在 simpleContent 元素内定义扩展或限定,就像这样:


<xs:element name="somename">
  <xs:complexType>
    <xs:simpleContent>
      <xs:extension base="basetype">
        .... 
        ....
      </xs:extension>
    </xs:simpleContent>
  </xs:complexType>
</xs:element>
或者:
<xs:element name="somename">
  <xs:complexType>
    <xs:simpleContent>
      <xs:restriction base="basetype">
        ....      
        ....
      </xs:restriction>
    </xs:simpleContent>
  </xs:complexType>
</xs:element>

提示: 请使用 extension 或 restriction 元素来扩展或限制元素的基本简易类型。 这里有一个 XML 元素的例子,”shoesize”,其中仅包含文本:


<shoesize country="france">35</shoesize>

下面这个例子声明了一个复合类型,其内容被定义为整数值,并且 “shoesize” 元素含有名为 “country” 的属性:


<xs:element name="shoesize">
  <xs:complexType>
    <xs:simpleContent>
      <xs:extension base="xs:integer">
        <xs:attribute name="country" type="xs:string" />
      </xs:extension>
    </xs:simpleContent>
  </xs:complexType>
</xs:element>

我们也可为 complexType 元素设定一个名称,并让 “shoesize” 元素的 type 属性来引用此名称(通过使用此方法,若干元素均可引用相同的复合类型):


<xs:element name="shoesize" type="shoetype"/>
<xs:complexType name="shoetype">
  <xs:simpleContent>
    <xs:extension base="xs:integer">
      <xs:attribute name="country" type="xs:string" />
    </xs:extension>
  </xs:simpleContent>
</xs:complexType>

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

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

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

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

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

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