课程表

Schema 教程

简单的类型

复杂的类型

数据类型

参考手册

工具箱
速查手册

XSD 空元素

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

空的复合元素不能包含内容,只能含有属性。

复合空元素:

一个空的 XML 元素:

  1. <product prodid="1345" />

上面的 "product" 元素根本没有内容。为了定义无内容的类型,我们就必须声明一个在其内容中只能包含元素的类型,但是实际上我们并不会声明任何元素,比如这样:

  1. <xs:element name="product">
  2. <xs:complexType>
  3. <xs:complexContent>
  4. <xs:restriction base="xs:integer">
  5. <xs:attribute name="prodid" type="xs:positiveInteger"/>
  6. </xs:restriction>
  7. </xs:complexContent>
  8. </xs:complexType>
  9. </xs:element>

在上面的例子中,我们定义了一个带有复合内容的复合类型。complexContent 元素给出的信号是,我们打算限定或者拓展某个复合类型的内容模型,而 integer 限定则声明了一个属性但不会引入任何的元素内容。

不过,也可以更加紧凑地声明此 "product" 元素:

  1. <xs:element name="product">
  2. <xs:complexType>
  3. <xs:attribute name="prodid" type="xs:positiveInteger"/>
  4. </xs:complexType>
  5. </xs:element>

或者您可以为一个 complexType 元素起一个名字,然后为 "product" 元素设置一个 type 属性并引用这个 complexType 名称(通过使用此方法,若干个元素均可引用相同的复合类型):

  1. <xs:element name="product" type="prodtype"/>
  2.  
  3. <xs:complexType name="prodtype">
  4. <xs:attribute name="prodid" type="xs:positiveInteger"/>
  5. </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号