课程表

Schema 教程

简单的类型

复杂的类型

数据类型

参考手册

工具箱
速查手册

XSD 仅含文本

当前位置:免费教程 » XML相关 » Schema

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

仅含文本的复合元素

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

  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>

或者:

  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",其中仅包含文本:

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

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

  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 属性来引用此名称(通过使用此方法,若干元素均可引用相同的复合类型):

  1. <xs:element name="shoesize" type="shoetype"/>
  2.  
  3. <xs:complexType name="shoetype">
  4. <xs:simpleContent>
  5. <xs:extension base="xs:integer">
  6. <xs:attribute name="country" type="xs:string" />
  7. </xs:extension>
  8. </xs:simpleContent>
  9. </xs:complexType>
转载本站内容时,请务必注明来自W3xue,违者必究。
 友情链接:直通硅谷  点职佳  北美留学生论坛

本站QQ群:前端 618073944 | Java 606181507 | Python 626812652 | C/C++ 612253063 | 微信 634508462 | 苹果 692586424 | C#/.net 182808419 | PHP 305140648 | 运维 608723728

W3xue 的所有内容仅供测试,对任何法律问题及风险不承担任何责任。通过使用本站内容随之而来的风险与本站无关。
关于我们  |  意见建议  |  捐助我们  |  报错有奖  |  广告合作、友情链接(目前9元/月)请联系QQ:27243702 沸活量
皖ICP备17017327号-2 皖公网安备34020702000426号