XSD Simple 元素

XML Schemas define the elements of your XML files.
XML Schemas(XML公式)定义了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"/>
 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值