XSD 混合内容的复合类型

来源:互联网 发布:数据魔方登录 编辑:程序博客网 时间:2024/04/27 21:46

A mixed complex type element can contain attributes, elements, and text.
混合内容的复合类型元素(XSD Complex Types Element With Mixed Content )可以含有属性,元素,和文本。


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公式声明了"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>