以文本方式查看主题

-  中文XML论坛 - 专业的XML技术讨论区  (http://bbs.xml.org.cn/index.asp)
--  『 DTD/XML Schema 』  (http://bbs.xml.org.cn/list.asp?boardid=23)
----  XSD中内置的数据类型(总结)  (http://bbs.xml.org.cn/dispbbs.asp?boardid=23&rootid=&id=52862)


--  作者:hongjuesir
--  发布时间:9/19/2007 1:14:00 PM

--  XSD中内置的数据类型(总结)
1.字符串数据类型(String Data Type)

字符串数据类型
请注意,所有以下的数据类型均衍生于字符串数据类型(除了字符串数据类本身)!

名称                   描述
ENTITIES   
ENTITY   
ID:在XML中提交ID属性的字符串(only used with schema attributes)
IDREF:在XML中提交IDREF属性的字符串(only used with schema attributes)
IDREFS language:包含合法的语言id的字符串
Name:包含合法XML名称的字符串
NCName:
NMTOKEN:在XML中提交NMTOKEN属性的字符串(only used with schema attributes)
NMTOKENS:
normalizedString:不包含换行符、回车或制表符的字符串
QName   
string:字符串
token:不包含换行符、回车或制表符、开头或结尾空格或者多个连续空格的字符串

对字符串数据类型的限定(Restriction)
可通字符串数据类型使用的限定:
enumeration
length
maxLength
minLength
pattern (NMTOKENS、IDREFS以及ENTITIES无法使用此约束)
whiteSpace

2.日期和时间数据类型

date:定义一个日期值
dateTime: 定义一个日期和时间值
duration :定义一个时间间隔
gDay: 定义日期的一个部分 - 天 (DD)
gMonth: 定义日期的一个部分 - 月 (MM)
gMonthDay: 定义日期的一个部分 - 月和天 (MM-DD)
gYear: 定义日期的一个部分 - 年 (YYYY)
gYearMonth: 定义日期的一个部分 - 年和月 (YYYY-MM)
time: 定义一个时间值

对日期数据类型的限定(Restriction)
enumeration
maxExclusive
maxInclusive
minExclusive
minInclusive
pattern
whiteSpace

3.数值数据类型

byte: 有正负的8位整数
decimal: 十进制数
int: 有正负的32位整数
integer: 整数值
long: 有正负的64位整数
negativeInteger: 仅包含负值的整数( .., -2, -1.)
nonNegativeInteger: 仅包含非负值的整数(0, 1, 2, ..)
nonPositiveInteger: 仅包含非正值的整数(.., -2, -1, 0)
positiveInteger: 仅包含正值的整数(1, 2, ..)
short: 有正负的16位整数
unsignedLong: 无正负的64位整数
unsignedInt: 无正负的32位整数
unsignedShort: 无正负的16位整数
unsignedByte: 无正负的8位整数

对数值数据类型的限定(Restriction)
enumeration
fractionDigits
maxExclusive
maxInclusive
minExclusive
minInclusive
pattern
totalDigits
whiteSpace

4.杂项数据类型(Miscellaneous Data Types)

逻辑数据类型(Boolean Data Type)
逻辑数据性被用来规定true或false值。

下面是一个关于某个scheme中逻辑声明的例子:

<xs:attribute name="disabled" type="xs:boolean"/>文档中的元素看上去应该类似这样:

<prize disabled="true">999</prize>注释:合法的布尔值是true、false、1以及0(表示false)。
二进制数据类型(Binary Data Types)
二进制数据类型被用来表达二进制形式的数据。

我们可使用两种二进制数据类型:

base64Binary (Base64编码的二进制数据)
hexBinary (十六进制编码的二进制数据)
下面是一个关于某个scheme中hexBinary声明的例子:

<xs:element name="blobsrc" type="xs:hexBinary"/>AnyURI数据类型(AnyURI Data Type)
anyURI数据类型被用来规定URI。

下面是一个关于某个scheme中anyURI声明的例子:

<xs:attribute name="src" type="xs:anyURI"/>文档中的元素看上去应该类似这样:

<pic src="http://www.w3schools.com/images/smiley.gif" />注释:假如某个URI含有空格,请用%20替换它们。

杂项数据类型(Miscellaneous Data Types)
名称 描述
anyURI   
base64Binary   
boolean   
double   
float   
hexBinary   
NOTATION   
QName   

对杂项数据类型的限定(Restriction)
可与杂项数据类型使用的限定:

enumeration (布尔数据类型无法使用此约束)
length (布尔数据类型无法使用此约束)
maxLength (布尔数据类型无法使用此约束)
minLength (布尔数据类型无法使用此约束)
pattern
whiteSpace


--  作者:zhaolei6689
--  发布时间:9/30/2007 2:18:00 PM

--  
哇,高人啊..能帮帮我吗..我在愁呢..能帮我做个XSD 去验证我的XML吗?谢谢.. Y.Y
<UWO>
    <Departments>
  <Department>
   <Name>Economics</Name>
   <Address>Social Science Centre, UWO, London, Ontario, Canada , N6A 5C2</Address>
   <Location>SSC 4071</Location>
   <Phone>519 661-3500 x83500</Phone>
   <Facsimile>519 661-3666 x83666</Facsimile>
   <Email>economics@uwo.ca</Email>
   <WEB>http://economics.uwo.ca</WEB>
  </Department>
  <Department>
   <Name>Political_science</Name>
   <Address>Social Science Centre, UWO, London, Ontario, Canada , N6A 5C2</Address>
   <Location>SSC 4154</Location>
   <Phone>519 661-3266 x83266</Phone>
   <Facsimile>519 661-3904 x83904</Facsimile>
   <Email>polisci-web@uwo.ca</Email>
   <WEB>http://politicalscience.uwo.ca</WEB>
   <SERVICES>
    <Service>
     <Name>Local_Government_program</Name>
     <Phone>519 661-2111 x80501</Phone>
     <Lacotion>SSC 4148</Lacotion>
     <WEB>http://localgovernment.uwo.ca</WEB>
    </Service>
    <Service>
     <Name>Politics_020E_course_Coordinator</Name>
     <Phone>519 661-2111 x85108</Phone>
     <Location>ssc 4149</Location>
    </Service>
   </SERVICES>
  </Department>
   </Departments>
</UWO>

--  作者:yihoo
--  发布时间:10/2/2007 5:26:00 PM

--  回复二楼的朋友
以下是引用zhaolei6689在2007-9-30 14:18:00的发言:
哇,高人啊..能帮帮我吗..我在愁呢..能帮我做个XSD 去验证我的XML吗?谢谢.. Y.Y
<UWO>
     <Departments>
   <Department>
    <Name>Economics</Name>
    <Address>Social Science Centre, UWO, London, Ontario, Canada , N6A 5C2</Address>
    <Location>SSC 4071</Location>
    <Phone>519 661-3500 x83500</Phone>
    <Facsimile>519 661-3666 x83666</Facsimile>
    <Email>economics@uwo.ca</Email>
    <WEB>http://economics.uwo.ca</WEB>
   </Department>
   <Department>
    <Name>Political_science</Name>
    <Address>Social Science Centre, UWO, London, Ontario, Canada , N6A 5C2</Address>
    <Location>SSC 4154</Location>
    <Phone>519 661-3266 x83266</Phone>
    <Facsimile>519 661-3904 x83904</Facsimile>
    <Email>polisci-web@uwo.ca</Email>
    <WEB>http://politicalscience.uwo.ca</WEB>
    <SERVICES>
     <Service>
      <Name>Local_Government_program</Name>
      <Phone>519 661-2111 x80501</Phone>
      <Lacotion>SSC 4148</Lacotion>此处修改为<Location>SSC 4148</Location>
      <WEB>http://localgovernment.uwo.ca</WEB>
     </Service>
     <Service>
      <Name>Politics_020E_course_Coordinator</Name>
      <Phone>519 661-2111 x85108</Phone>
      <Location>ssc 4149</Location>
     </Service>
    </SERVICES>
   </Department>
    </Departments>
</UWO>


以下是为上面的XML配的一个最基本的schema
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="unqualified">
 <xs:element name="UWO">
  <xs:complexType>
   <xs:sequence>
    <xs:element name="Departments">
     <xs:complexType>
      <xs:sequence>
       <xs:element ref="Department" maxOccurs="unbounded"/>
      </xs:sequence>
     </xs:complexType>
    </xs:element>
   </xs:sequence>
  </xs:complexType>
 </xs:element>
 <xs:element name="Department">
  <xs:complexType>
   <xs:sequence>
    <xs:element name="Name" type="xs:string"/>
    <xs:element name="Address" type="xs:string"/>
    <xs:element name="Location" type="xs:string"/>
    <xs:element name="Phone" type="xs:string"/>
    <xs:element name="Facsimile" type="xs:string"/>
    <xs:element name="Email" type="xs:string"/>
    <xs:element name="WEB" type="xs:string"/>
    <xs:element ref="SERVICES" minOccurs="0" maxOccurs="1"/>
   </xs:sequence>
  </xs:complexType>
 </xs:element>
 <xs:element name="SERVICES">
  <xs:complexType>
   <xs:sequence>
    <xs:element name="Service" maxOccurs="unbounded">
     <xs:complexType>
      <xs:sequence>
       <xs:element name="Name" type="xs:string"/>
       <xs:element name="Phone" type="xs:string"/>
       <xs:element name="Location" type="xs:string"/>
       <xs:element name="WEB" type="xs:string" minOccurs="0" maxOccurs="1"/>
      </xs:sequence>
     </xs:complexType>
    </xs:element>
   </xs:sequence>
  </xs:complexType>
 </xs:element>
</xs:schema>


--  作者:yxli
--  发布时间:12/30/2007 9:11:00 PM

--  
谢谢,我正需要这些知识了
--  作者:1500053
--  发布时间:5/10/2008 9:18:00 PM

--  
非常感谢
W 3 C h i n a ( since 2003 ) 旗 下 站 点
苏ICP备05006046号《全国人大常委会关于维护互联网安全的决定》《计算机信息网络国际联网安全保护管理办法》
14,906.250ms