当前位置: 首页 > 网络学院 > XML相关教程 > Schema (XSD) > XSD 简单元素
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元素。它不可以再包含其它元素或属性。
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.
你可以通过为数据类型添加限定条件来限制它的内容;或者,你可以要求数据与指定的样式相匹配。
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本身包含多种内置的数据类型。最常见的类型如下:
Here are some XML elements:
下面列举了一些XML元素:
<lastname>Refsnes</lastname> |
And here are the corresponding simple element definitions:
下面列举了相对简单的元素定义:
<xs:element name="lastname" type="xs:string"/> |
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"/> |