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

XSD 复合类型 - 仅含元素

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

“仅含元素”的复合类型元素是只能包含其他元素的元素。

复合类型仅包含元素

XML 元素,"person",仅包含其他的元素:

<person>
<firstname>John</firstname>
<lastname>Smith</lastname>
</person>

您可在 schema 中这样定义 "person" 元素:

<xs:element name="person">
  <xs:complexType>
    <xs:sequence>
      <xs:element name="firstname" type="xs:string"/>
      <xs:element name="lastname" type="xs:string"/>
    </xs:sequence>
  </xs:complexType>
</xs:element>

请留意这个 <xs:sequence>。它意味着被定义的元素必须按上面的次序出现在 "person" 元素中。

或者您可以为 complexType 元素设定一个名称,并让 "person" 元素的 type 属性来引用此名称(如使用此方法,若干元素均可引用相同的复合类型):

<xs:element name="person" type="persontype"/>

<xs:complexType name="persontype">
  <xs:sequence>
    <xs:element name="firstname" type="xs:string"/>
    <xs:element name="lastname" type="xs:string"/>
  </xs:sequence>
</xs:complexType>

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

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

快速入口

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

其它栏目

· 建站教程
· 365学习

业务咨询

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

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

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