当前位置:K88软件开发文章中心编程语言XmlSchema01 → 文章内容

XML Schema 复合类型 – 混合内容

减小字体 增大字体 作者:佚名  来源:网上搜集  发布时间:2019-1-13 11:10:48

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>

XML Schema 复合类型 – 混合内容