XSD 仅含文本复合元素_Android, Python及开发编程讨论区_Weblogic技术|Tuxedo技术|中间件技术|Oracle论坛|JAVA论坛|Linux/Unix技术|hadoop论坛_联动北方技术论坛  
网站首页 | 关于我们 | 服务中心 | 经验交流 | 公司荣誉 | 成功案例 | 合作伙伴 | 联系我们 |
联动北方-国内领先的云技术服务提供商
»  游客             当前位置:  论坛首页 »  自由讨论区 »  Android, Python及开发编程讨论区 »
总帖数
1
每页帖数
101/1页1
返回列表
0
发起投票  发起投票 发新帖子
查看: 1910 | 回复: 0   主题: XSD 仅含文本复合元素        下一篇 
    本主题由 koei123 于 2015-7-14 11:05:57 移动
huan.liu
注册用户
等级:新兵
经验:72
发帖:58
精华:0
注册:2011-11-23
状态:离线
发送短消息息给huan.liu 加好友    发送短消息息给huan.liu 发消息
发表于: IP:您无权察看 2015-7-6 10:54:10 | [全部帖] [楼主帖] 楼主

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

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

<xs:element name="某个名称">
<xs:complexType>
<xs:simpleContent>
<xs:extension base="basetype">
....
....
</xs:extension>
</xs:simpleContent>
</xs:complexType>
< /xs:element>或者:
<xs:element name="某个名称">
<xs:complexType>
<xs:simpleContent>
<xs:restriction base="basetype">
....
....
</xs:restriction>
</xs:simpleContent>
</xs:complexType>
< /xs:element>提示:请使用 extension 或 restriction 元素来扩展或限制元素的基本简易类型。


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

<shoesize country="france">35</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>我们也可为 complexType 元素设定一个名称,并让 "shoesize" 元素的 type 属性来引用此名称(通过使用此方法,若干元素均可引用相同的复合类型):

<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>
========================================


12.XSD 带有混合内容的复合类型

混合的复合类型可包含属性、元素以及文本。
带有混合内容的复合类型
XML 元素,"letter",含有文本以及其他元素:

<letter>
Dear Mr.<name>John Smith</name>.
Your order <orderid>1032</orderid>
will be shipped on <shipdate>2001-07-13</shipdate>.
< /letter>下面这个 schema 声明了这个 "letter" 元素:
<xs:element name="letter">
<xs:complexType mixed="true">
<xs:sequence>
<xs:element name="name" type="xs:string"/>
<xs:element name="orderid" type="xs:positiveInteger"/>
<xs:element name="shipdate" type="xs:date"/>
</xs:sequence>
</xs:complexType>


< /xs:element>注释:为了使字符数据可以出现在 "letter" 的子元素之间,mixed 属性必须被设置为 "true"。<xs:sequence> 标签 (name、orderid 以及 shipdate ) 意味着被定义的元素必须依次出现在 "letter" 元素内部。

我们也可以为 complexType 元素起一个名字,并让 "letter" 元素的 type 属性引用 complexType 的这个名称(通过这个方法,若干元素均可引用同一个复合类型):

<xs:element name="letter" type="lettertype"/>
< xs:complexType name="lettertype" mixed="true">
<xs:sequence>
<xs:element name="name" type="xs:string"/>
<xs:element name="orderid" type="xs:positiveInteger"/>
<xs:element name="shipdate" type="xs:date"/>
</xs:sequence>
< /xs:complexType>


--转自 北京联动北方科技有限公司

该贴由koei123转至本版2015-7-14 11:05:57



赞(0)    操作        顶端 
总帖数
1
每页帖数
101/1页1
返回列表
发新帖子
请输入验证码: 点击刷新验证码
您需要登录后才可以回帖 登录 | 注册
技术讨论