XML Schema学习笔记(二)

Data Types

1.    String Data Types

1.1            String Data Type

可包含字符、缩进、回车、tab

 

在这样的Schema定义中:

<xs:element name=”customer” type=”xs:string”/>

XML中的元素可以是这样:

<customer>John Smith</customer>

也可以是这样:

<customer>   John Smith    </customer>

XML处理器将不会修改使用的string数据类型的值

 

1.2            NormalizedString Data Type

normalizedString类型由string数据类型继承而来

normalizedString类型也包含字符,但是XML处理器将替换缩进、回车以及制表符

上面的第三个例子,将用space代替tab

 

1.3            Token Data Type

也继承自String,但XML Processor将去除feedscarriage returnstabs、行首空格和行尾空格、多空格。

上面的第三个例子,tab将被去除

 

1.4            String Data Types

所有从string继承的类型

Name

Description

ENTITIES

 

ENTITY

 

ID

A string that represents the ID attribute in XML (only used with schema attributes)

IDREF

A string that represents the IDREF attribute in XML (only used with schema attributes)

IDREFS

 

language

A string that contains a valid language id

Name

A string that contains a valid XML name

NCName

 

NMTOKEN

A string that represents the NMTOKEN attribute in XML (only used with schema attributes)

NMTOKENS

 

normalizedString

A string that does not contain line feeds, carriage returns, or tabs

QName

 

string

A string

token

A string that does not contain line feeds, carriage returns, tabs, leading or trailing spaces, or multiple spaces

 

1.5            可用于String数据类型的约束

ü         enumeration

ü         length

ü         maxLength

ü         minLength

ü         pattern(NMTOKENS,IDREFSENTITIES不能用于这种约束)

ü         whiteSpace

 

2.    Date and Time Data Types

2.1            Date Data Type

YYYY-MM-DD

schema: <xs:element name=”start” type=”xs:date”/>

xml element: <start> 2004-09-24 </start>

Time Zones

要指定时区,可以输入一个UTC日期,然后加一个Z

<start> 2002-09-24 Z</start>

或者加上正负时间差来表示时间偏移量

<start> 2002-09-24 -06:00</start>

 

OR

 

<start> 2002-09-24 +06:00</start>

 

2.2            Time Data Type

hh:mm:ss

schema: <xs:element name=”start” type=”xs:time”/>

xml element: <start>09:00:00</start>

也可能像这样:<start>09:30:10.5</start>

Time Zones

时区同上

 

2.3            DateTime Data Type

YYYY-MM-DDThh:mm:ss  注意:T表示开始时间部分

schema: <xs:element name=”startdate” type=”xs:dateTime”/>

xml element: <start> 2002-05-30 T09:30:10.5</start>

Time Zones

直接加在最后: 2002-05-30 T09:30:10-06:00 2002-05-30 T09:30:10+06:00

 

2.4            Duration Data Type

duration用于标识时间间隔, PnYnMnDTnHnMnS

P是必须的,用于标识是一个时间段

n表示具体的年、月、日、时、分、秒的数量

schema: <xs:element name=”period” type=”xs:duration”>

<period>P5Y</period> 五年

<period>P5Y 2M 10DT15H</period>五年两个月十天十五小时

<period>PT15H</period> 15小时,只表示时间也需加T

负时间段:

要指明一个负时间段,在前面加负号

<period>-P10D</period>   10

 

2.5            Date and Time Data Types

Name

Description

date

Defines a date value

dateTime

Defines a date and time value

duration

Defines a time interval

gDay

Defines a part of a date - the day (DD)

gMonth

Defines a part of a date - the month (MM)

gMonthDay

Defines a part of a date - the month and day (MM-DD)

gYear

Defines a part of a date - the year (YYYY)

gYearMonth

Defines a part of a date - the year and month (YYYY-MM)

time

Defines a time value

 

 

2.6            Restrictions On Date Data Types

ü         enumeration

ü         maxExclusive

ü         maxInclusive

ü         minExclusive

ü         minInclusive

ü         pattern

ü         whiteSpace

3.    Numeric Data Types

3.1 Decimal Data Type

Schema: <xs:element name=”prize” type=”xs:decimal”/>

xml element:

<prize>999.50</prize> 可以有个后面的0

<prize>+999.50</prize> 前面可以添加正负号

<prize>-999.50</prize>

3.2 Integer Data Type

整数,可以添加正负号

 

3.3 Numeric Data Type

Name

Description

byte

A signed 8-bit integer

decimal

A decimal value

int

A signed 32-bit integer

integer

An integer value

long

A signed 64-bit integer

negativeInteger

An integer containing only negative values ( .., -2, -1.)

nonNegativeInteger

An integer containing only non-negative values (0, 1, 2, ..)

nonPositiveInteger

An integer containing only non-positive values (.., -2, -1, 0)

positiveInteger

An integer containing only positive values (1, 2, ..)

short

A signed 16-bit integer

unsignedLong

An unsigned 64-bit integer

unsignedInt

An unsigned 32-bit integer

unsignedShort

An unsigned 16-bit integer

unsignedByte

An unsigned 8-bit integer

byte: 一个8位的带符号的整数,所以范围为-128~12727次幂)

int: 32位,不同于integer

long: 64位,这时候为最大值为9223372036854775807,为19位,超过了decimal

short: 16

 

3.4 Restrictions on Numeric Data Types

ü         enumeration

ü         fractionDigits

ü         maxExclusive

ü         maxInclusive

ü         minExclusive

ü         minInclusive

ü         pattern

ü         totalDigits

ü         whiteSpace

 

4.    Miscellaneous Data Types

其它的数据类型包括:

boolean,base64Binary,hexBinary,float,double,anyURI,QName,NOTATION

 

4.1 Boolean Data Type

可以为四个值true/false/1/0,其余均不合法

 

4.2 Binary Data Types

有两种binary类型:

base64Binary(Base64-encoded binary data)

hexBinary(hexadecimal-encoded binary data)

 

4.3 AnyURI Data Type

表示一个URI

schema: <xs:attribute name=”src” type=”xs:anyURI”/>

xml: <pic src=”http://www.w3schools.com/images/siley.gif”/>

注意:如果URI包含空格,用”% 20” 代替

 

4.4 Miscellaneous Data Types

Name

Description

anyURI

 

base64Binary

 

boolean

 

double

 

float

 

hexBinary

 

NOTATION

 

QName

 

 

 

4.5 Restrictions on Miscellaneous Data Types

ü         enumeration(boolean不能使用)

ü         lengthboolean不能使用)

ü         maxLengthboolean不能使用)

ü         minLengthboolean不能使用)

ü         patter

ü         whiteSpace

 

5.    XSD Elements

Element

Explanation

all

Specifies that the child elements can appear in any order. Each child element can occur 0 or 1 time

annotation

Specifies the top-level element for schema comments

any

Enables the author to extend the XML document with elements not specified by the schema

anyAttribute

Enables the author to extend the XML document with attributes not specified by the schema

appInfo

Specifies information to be used by the application (must go inside annotation)

attribute

Defines an attribute

attributeGroup

Defines an attribute group to be used in complex type definitions

choice

Allows only one of the elements contained in the <choice> declaration to be present within the containing element

complexContent

Defines extensions or restrictions on a complex type that contains mixed content or elements only

complexType

Defines a complex type element

documentation

Defines text comments in a schema (must go inside annotation)

element

Defines an element

extension

Extends an existing simpleType or complexType element

field

Specifies an XPath expression that specifies the value used to define an identity constraint

group

Defines a group of elements to be used in complex type definitions

import

Adds multiple schemas with different target namespace to a document

include

Adds multiple schemas with the same target namespace to a document

key

Specifies an attribute or element value as a key (unique, non-nullable, and always present) within the containing element in an instance document

keyref

Specifies that an attribute or element value correspond to those of the specified key or unique element

list

Defines a simple type element as a list of values

notation

Describes the format of non-XML data within an XML document

redefine

Redefines simple and complex types, groups, and attribute groups from an external schema

restriction

Defines restrictions on a simpleType, simpleContent, or a complexContent

schema

Defines the root element of a schema

selector

Specifies an XPath expression that selects a set of elements for an identity constraint

sequence

Specifies that the child elements must appear in a sequence. Each child element can occur from 0 to any number of times

simpleContent

Contains extensions or restrictions on a text-only complex type or on a simple type as content and contains no elements

simpleType

Defines a simple type and specifies the constraints and information about the values of attributes or text-only elements

union

Defines a simple type as a collection (union) of values from specified simple data types

unique

Defines that an element or an attribute value must be unique within the scope

 

 

6.    XSD Restrictions/Facets for Datatypes

Constraint

Description

enumeration

Defines a list of acceptable values

fractionDigits

Specifies the maximum number of decimal places allowed. Must be equal to or greater than zero

length

Specifies the exact number of characters or list items allowed. Must be equal to or greater than zero

maxExclusive

Specifies the upper bounds for numeric values (the value must be less than this value)

maxInclusive

Specifies the upper bounds for numeric values (the value must be less than or equal to this value)

maxLength

Specifies the maximum number of characters or list items allowed. Must be equal to or greater than zero

minExclusive

Specifies the lower bounds for numeric values (the value must be greater than this value)

minInclusive

Specifies the lower bounds for numeric values (the value must be greater than or equal to this value)

minLength

Specifies the minimum number of characters or list items allowed. Must be equal to or greater than zero

pattern

Defines the exact sequence of characters that are acceptable

totalDigits

Specifies the exact number of digits allowed. Must be greater than zero

whiteSpace

Specifies how white space (line feeds, tabs, spaces, and carriage returns) is handled

 

 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值