XSD 复合文字 - 纯元素

A complex text-only element can contain text and attributes.
一个复合只含文本元素(Complex Text-Only Elements)可以含有文本和属性。


Complex Text-Only Elements
复合只含文本元素(Complex Text-Only Elements)

This type contains only simple content (text and attributes), therefore we add a simpleContent element around the content. When using simple content, you must define an extension OR a restriction within the simpleContent element, like this:
这种类型只含有简单内容(文本和属性),因此我们在内容周围添加一个simpleContent元素,当用到简单内容时,你必须在simpleContent元素里定义一个扩展或约束,就像这样:

<xs:element name="somename">

  <xs:complexType>
    <xs:simpleContent>
      <xs:extension base="basetype">
        ....
        ....
      </xs:extension>     
    </xs:simpleContent>
  </xs:complexType>

</xs:element>

OR

<xs:element name="somename">
  <xs:complexType>
    <xs:simpleContent>
      <xs:restriction base="basetype">

        ....
        ....
      </xs:restriction>     
    </xs:simpleContent>
  </xs:complexType>
</xs:element>

Tip: Use the extension/restriction element to expand or to limit the base simple type for the element.
提示:用extension/restriction元素扩展或限制元素的基本简单类型(base simple type)。

Here is an example of an XML element, "shoesize", that contains text-only:
这儿是只含有文本的一个XML元素, "shoesize":

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

The following example declares a complexType, "shoesize". The content is defined as an integer value, and the "shoesize" element also contains an attribute named "country":
下面的例子声明了一个复合类型,"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>

We could also give the complexType element a name, and let the "shoesize" element have a type attribute that refers to the name of the complexType (if you use this method, several elements can refer to the same complex type):
我们可以给complexType元件起个名字,让"shoesize"元件有种类属性,种类属性的名字就是complexType元件的名字。(如果你用这种方法,几个元素指的可以是相同的复合类型)

<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>
 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值