以文本方式查看主题

-  计算机科学论坛  (http://bbs.xml.org.cn/index.asp)
--  『 XML基础 』  (http://bbs.xml.org.cn/list.asp?boardid=1)
----  [Schema教程]十二 XSD 带有混合内容的复合类型  (http://bbs.xml.org.cn/dispbbs.asp?boardid=1&rootid=&id=87450)


--  作者:yjihcihc
--  发布时间:11/3/2010 3:29:00 PM

--  [Schema教程]十二 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>
本文转载八度网:http://www.wrsaw.cn/Article/ShowArticle.asp?ArticleID=969


--  作者:hjx_221
--  发布时间:12/7/2010 12:18:00 PM

--  
谢谢楼主


W 3 C h i n a ( since 2003 ) 旗 下 站 点
苏ICP备05006046号《全国人大常委会关于维护互联网安全的决定》《计算机信息网络国际联网安全保护管理办法》
46.875ms