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

XML Schemas define the elements of your XML files.
XML Schemas定义了XML文件的元素。

A simple element is an XML element that contains only text. It cannot contain any other elements or attributes.
简单元素是只包含文本的XML元素。它不可以再包含其它元素或属性。


What is a Simple Element?
什么是简单元素?

A simple element is an XML element that can contain only text. It cannot contain any other elements or attributes.
简单元素是只包含文本的XML元素。它不可以再包含其它元素或属性。

However, the "only text" restriction is quite misleading. The text can be of many different types. It can be one of the types included in the XML Schema definition (boolean, string, date, etc.), or it can be a custom type that you can define yourself.
然而,“只包含文本”这个限定条件是非常容易引起误解的。文本可以包含多种不同类型。它可以是XML Schema定义中的文本类型之一(逻辑值、字符串、日期,等等),也可以是自定义文本类型。

You can also add restrictions (facets) to a data type in order to limit its content, or you can require the data to match a specific pattern.
你可以通过为数据类型添加限定条件来限制它的内容;或者,你可以要求数据与指定的样式相匹配。


Defining a Simple Element
定义一个简单元素

The syntax for defining a simple element is:
定义一个简单元素的语法如下:

<xs:element name="xxx" type="yyy"/>

where xxx is the name of the element and yyy is the data type of the element.
上述案例中, xxx是元素名称,yyy是元素的数据类型。

XML Schema has a lot of built-in data types. The most common types are:
XML Schema本身包含多种内置的数据类型。最常见的类型如下:

  • xs:string
    xs:字符
  • xs:decimal
    xs: 小数
  • xs:integer
    xs:整数
  • xs:boolean
    xs:逻辑值
  • xs:date
    xs:日期
  • xs:time
    xs:时间

Example
案例

Here are some XML elements:
下面列举了一些XML元素:

<lastname>Refsnes</lastname>
<age>36</age>
<dateborn>1970-03-27</dateborn>

And here are the corresponding simple element definitions:
下面列举了相对简单的元素定义:

<xs:element name="lastname" type="xs:string"/>

<xs:element name="age" type="xs:integer"/>
<xs:element name="dateborn" type="xs:date"/>

 


Default and Fixed Values for Simple Elements
简单元素的默认值和固定值

Simple elements may have a default value OR a fixed value specified.
简单元素可以包含指定的默认值或固定值。

A default value is automatically assigned to the element when no other value is specified.
当未指定其它值时,属性会自动设置默认值。

In the following example the default value is "red":
下述案例的默认值是"red":

<xs:element name="color" type="xs:string" default="red"/>

A fixed value is also automatically assigned to the element, and you cannot specify another value.
固定值是也是系统自动分派给属性的。并且,一旦指定了固定值,你就不能指定其它值了。

In the following example the fixed value is "red":
下述案例的固定值是"red":

<xs:element name="color" type="xs:string" fixed="red"/>

评论 (1) 1 All

登陆 | 还没注册?