当前位置: 首页 > 网络学院 > 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   浏览: 698 ::
收藏到网摘: n/a

A complex text-only element can contain text and attributes.
一个复合纯文本元素可以包含文本和属性。


Complex Text-Only Elements
复合纯文本元素

This type contains only simple content (text and attributes), therefore we add a simpleContent element around the content. When using simple content, you must define an extension OR a restriction within the simpleContent element, like this:
这种类型只包含简单的内容(文本和属性),因此,我们需要在内容周围添加一个simpleContent元素;当使用简单内容时,你必须在simpleContent元素中定义一个扩展 [ extension ] 或约束 [ restriction ],如下所示:

<xs:element name="somename">

<xs:complexType>
<xs:simpleContent>
<xs:extension base="basetype">
....
....
</xs:extension>
</xs:simpleContent>
</xs:complexType>

</xs:element>

OR

<xs:element name="somename">
<xs:complexType>
<xs:simpleContent>
<xs:restriction base="basetype">

....
....
</xs:restriction>
</xs:simpleContent>
</xs:complexType>
</xs:element>

Tip: Use the extension/restriction element to expand or to limit the base simple type for the element.
提示:可以使用 extension / restriction 元素来扩展或约束元素的基本简单类型。

Here is an example of an XML element, "shoesize", that contains text-only:
下面列举了一个只包含文本的XML元素"shoesize":

<shoesize country="france">35</shoesize>

The following example declares a complexType, "shoesize". The content is defined as an integer value, and the "shoesize" element also contains an attribute named "country":
下述案例声明了一个复合类型元素"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>

We could also give the complexType element a name, and let the "shoesize" 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元素定义一个名称,让"shoesize"元素包含种类属性。种类属性的名称就是complexType元素的名称(如果你用上述方法,几个元素可以引用相同的复合类型):

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

评论 (0) All

登陆 | 还没注册?