当前位置: 首页 > 网络学院 > XML相关教程 > Schema (XSD) > XSD 混合内容的复合类型

Schema (XSD)
Schema (XSD) 介绍
为何使用 XML Schemas?
如何定制 XSD
XSD - <schema>元素
XSD 简单元素
XSD 属性
XSD 约束面
XSD 复合元素
XSD 复合空元素
XSD 复合纯元素
XSD 复合纯文本
XSD 混合内容的复合类型
XSD 指示器复合类型
XSD <any> 元素
XSD <anyAttribute> 元素
XSD 元素替代
XSD 实例
XSD 字符串数据类型
XSD 日期数据类型
XSD 小数数据类型

Schema (XSD) 中的 XSD 混合内容的复合类型


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-03-01   浏览: 771 ::
收藏到网摘: n/a

A mixed complex type element can contain attributes, elements, and text.
XSD混合内容的复合类型元素可以包含属性、元素和文本。


Complex Types with Mixed Content
混合内容的复合类型

An XML element, "letter", that contains both text and other elements:
一个XML元素,"letter"既可以包含文本又可以包含其它元素:

<letter>
Dear Mr.<name>John Smith</name>.
Your order <orderid>1032</orderid>
will be shipped on <shipdate>2001-07-13</shipdate>.

</letter>

The following schema declares the "letter" element:
下面的XML 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>

Note: To enable character data to appear between the child-elements of "letter", the mixed attribute must be set to "true". The <xs:sequence> tag means that the elements defined (name, orderid and shipdate) must appear in that order inside a "letter" element.
注意:为了使字符数据能出现在"letter"子元素之间,mixed 属性必须设置为"true"。<xs:sequence>标签指定了已定义的元素(name、orderid 和 shipdate)在"letter"元素中必须以指定的顺序出现。

We could also give the complexType element a name, and let the "letter" element have a type attribute that refers to the name of the complexType (if you use this method, several elements can refer to the same complex type):
我们可以为这个complexType元素定义一个名称,并且让"letter"元素包含一个引用了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>

评论 (0) All

登陆 | 还没注册?