您现在的位置: 365建站网 > 建站教程 > Schema 教程 > XSD 仅含文本复合元素

XSD 仅含文本复合元素

此节有 298 人学习过     参与评论

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

仅含文本的复合元素

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

</>code

  1. <xs:element name="某个名称">
  2. <xs:complexType>
  3. <xs:simpleContent>
  4. <xs:extension base="basetype">
  5. ....
  6. ....
  7. </xs:extension>
  8. </xs:simpleContent>
  9. </xs:complexType>
  10. </xs:element>

或者:

</>code

  1. <xs:element name="某个名称">
  2. <xs:complexType>
  3. <xs:simpleContent>
  4. <xs:restriction base="basetype">
  5. ....
  6. ....
  7. </xs:restriction>
  8. </xs:simpleContent>
  9. </xs:complexType>
  10. </xs:element>

提示:请使用 extension 或 restriction 元素来扩展或限制元素的基本简易类型。

这里有一个 XML 元素的例子,"shoesize",其中仅包含文本:

</>code

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

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

</>code

  1. <xs:element name="shoesize">
  2. <xs:complexType>
  3. <xs:simpleContent>
  4. <xs:extension base="xs:integer">
  5. <xs:attribute name="country" type="xs:string" />
  6. </xs:extension>
  7. </xs:simpleContent>
  8. </xs:complexType>
  9. </xs:element>

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

</>code

  1. <xs:element name="shoesize" type="shoetype"/>
  2. <xs:complexType name="shoetype">
  3. <xs:simpleContent>
  4. <xs:extension base="xs:integer">
  5. <xs:attribute name="country" type="xs:string" />
  6. </xs:extension>
  7. </xs:simpleContent>
  8. </xs:complexType>

如对本文有疑问,请提交到交流论坛,广大热心网友会为你解答!! 点击进入论坛

您可能感兴趣的文章:

发表评论 (298人查看0条评论)
请自觉遵守互联网相关的政策法规,严禁发布色情、暴力、反动的言论。
昵称:
最新评论
------分隔线----------------------------
Schema 教程目录

快速入口

· 365软件
· 杰创官网
· 建站工具
· 网站大全

其它栏目

· 建站教程
· 365学习

业务咨询

· 技术支持
· 服务时间:9:00-18:00
365建站网二维码

Powered by 365建站网 RSS地图 HTML地图

copyright © 2013-2024 版权所有 鄂ICP备17013400号