1.   XML约束规则 
a)        出现在最顶层的元素的集合。 
b)        对每个元素,有效属性和嵌套元素的集合。 
c)        对一个元素的每个可选属性,如果属性省略,提供默认值。 
d)        在顶层和任何的嵌套层上,同等元素允许的顺序。 
e)        在顶层和任何的嵌套层上,一个元素要求的和被允许的出现次数。 
f)        对每个元素,它是否可以包含非结构化的文本(称为“CDATA”)。 
  
2.   数据类型列表:
  
  
 
3.   值空间 
a)        Serialization Space:文档当中实际存储的内容。(实际存储) 
b)        Parsed Space:用Unicode表示的文档内容。(标准存储) 
c)        Lexical Space:文档内容的表示值。(表示值) 
d)        Value Space:文档内容的实际值。(实际值) 
例子: 
<a>1.00</a> 
<b>1.0</b> 
     假定<a>,<b>的类型都为decimal 
| 
    | 
 S Space  | 
 P Space  | 
 L Space  | 
 V Space  |  
| 
 1.00  | 
 31 2E 30 30  | 
 00 31 00 2E 00 30 00 30  | 
 1.00  | 
 1  |  
| 
 1.0  | 
 31 2E 30  | 
 00 31  00 2E 00 30  | 
 1.0  | 
 1  |    
  
4.   空格处理 
a)        空格替换(Serialization Space -> Parsed Space) 
指将所有的Tab(#x9),换行(#xA)和回车(#xD)都替换为空格(#x20)。 
b)        空格折叠(Parsed Space -> Lexical Space) 
指删除所有位于开始和结束位置的空格,并把中间所有相邻的空格合并为一个空格。 
  
5.   数据类型表示 
任一数据类型都通过一三元组(value space,lexical space,facets)进行表示。 
  
6.   字符串类型分支: 
a)        结构图:
  
  
 
b)        概述: 
主要用于表示与字符串相关的数据,这部分的类型一般都被认为是无序的。其中string类型是这部分的基类,他是唯一一种没有经过空格替换和空格折叠的类型。而normalizedString是表示经过了空格替换而没有经过空格折叠的类型,token则是用于表示既经过了空格替换又经过了空格折叠的类型。这三种类型都不用于表征某一特定类型。当需要某一特定类型时,可以使用token的更具体的子类,例如,当需要表示语言时可使用language,当需要表示某一名称时可使用Name,当需要表示ID值时可使用ID,当需要表示带名字空间的限定名时,可使用QName等。 
  
7.   数值类型分支: 
a)        结构图:
  
  
 
b)        概述: 
主要用于表示与数值相关的概念,这部分的数据一般都是有序的。其中float和double用于表示IEEE 754标准的浮点数。decimal是数字的基类,他可以表示任意形式的数字,integer主要表示正数,通过对integer增加不同的facet,来限制他的值空间,我们可以得到其他具体的子类。 
  
8.   时间类型分支: 
a)        结构图:
  
  
 
b)        概述: 
时间部分的类型大部分都是半有序的类型,而且与前述的两种类型不同,他们主要不是考互相集成和扩展得到的,而是都从基础类型中扩展而来。其中duration用于表示时间段的概念,他用于描述一个时间的跨度,而其他的类型都是一个时间点的概念,用于描述某一特定的时间点。 
  
  
9.   自定义类型 
除了内建类型之外,我们还可以通过Schema提供的扩展机制,进行自定义类型定义。其中扩展机制包括以下几种: 
a)        restriction 
通过约束基类的Value Space来创建新类型。 
                      i.              语法: 
<restriction 
  base = QName 
  id = ID 
  {any attributes with non-schema namespace . . .}> 
  Content: (annotation?, (simpleType?, (minExclusive | minInclusive | maxExclusive | maxInclusive | totalDigits | fractionDigits | length | minLength | maxLength | enumeration | whiteSpace | pattern)*)) 
</restriction> 
  
                   ii.              例子: 
Schema: 
<simpleType name='holidays'> 
<restriction base='gMonthDay'> 
<enumeration value='--01-01'/> 
<enumeration value='--07-04'/> 
<enumeration value='--12-25'/> 
</restriction> 
</simpleType> 
  
XML: 
<a holidays="--01-01"/> (正确) 
<a holidays="--01-02"/> (错误) 
  
b)        list 
用于表示由某一种类型组成的列表。通过itemType属性指定。 
                      i.              语法: 
<list 
  id = ID 
  itemType = QName 
  {any attributes with non-schema namespace . . .}> 
  Content: (annotation?, simpleType?) 
</list> 
  
                   ii.              例子: 
Schema: 
<simpleType name='listOfFloat'> 
  <list itemType='float'/> 
</simpleType> 
XML: 
<a>1.0 2.0 3.1</a>(正确) 
<a>1.0 32</a> (错误) 
  
c)        union 
用于表示由多种类型组成的联合。 
                      i.              语法: 
<union 
  id = ID 
  memberTypes = List of QName 
  {any attributes with non-schema namespace . . .}> 
  Content: (annotation?, simpleType*) 
</union> 
  
                   ii.              例子: 
Schema: 
<xsd:simpleType> 
<xsd:union> 
<xsd:simpleType> 
<xsd:restriction base="xsd:positiveInteger"> 
<xsd:minInclusive value="8"/> 
<xsd:maxInclusive value="72"/> 
</xsd:restriction> 
</xsd:simpleType> 
<xsd:simpleType> 
<xsd:restriction base="xsd:string"> 
<xsd:enumeration value="small"/> 
<xsd:enumeration value="medium"/> 
<xsd:enumeration value="large"/> 
</xsd:restriction> 
</xsd:simpleType> 
</xsd:union> 
</xsd:simpleType> 
  
XML: 
<font size='large'>A header</font>(正确) 
<font size='7'>this is a test</font>(错误) 
  
10.facet 
在restriction中出现的,用于约束Value Space的元素被称为“facet”。每种基础类型都规定了他可以使用的facet集合,详情可以参考Schema规范的Datatypes部分。另外,当我们从某一类型通过restriction进行扩展时,可能会在父,子类型之间使用了相同的facet,而根据facet的不同,Schema对此有不同的要求。 
  
a)        进一步约束值的facet 
对于enumeration, fractionDigits,maxExclusive,maxInclusive,maxLength,minExclusive,minInclusive,minLength和totalDigits,如果我们在子类型当中定义了与父类型相同的facet,那么对于facet的值,我们只能进一步进行约束,即子类型定义的Value Space必须是父类型的子集。例如,以下是一个错误的例子,因为子类型的Value Space不是父类型Value Space的子集。 
     <xs:simpleType name="minInclusive"> 
<xs:restriction base="xs:float"> 
<xs:minInclusive value="10"/> 
</xs:restriction> 
</xs:simpleType> 
  
<xs:simpleType name="minInclusive2"> 
<xs:restriction base="minInclusive"> 
<xs:minInclusive value="0"/> 
</xs:restriction> 
</xs:simpleType> 
  
b)        不能修改值的facet 
对于length,子类型不允许修改父类型定义的length值。 
  
c)        取值的交集的facet 
对于pattern,当父,子类型都定义了该facet时,两个pattern的值都会被使用。 
  
d)        特殊的facet 
对于一般的facet来说,他们都是用来对Value Space进行约束的,而whiteSpace则是唯一的一个特例。该facet的作用时机是在Lexical Space之前,因此他是唯一一个有可能扩展了Lexical Space的facet。例如: 
<xs:simpleType name="greetings"> 
<xs:restriction base="xs:string"> 
<xs:whiteSpace value="replace"/> 
<xs:enumeration value="hi"/> 
<xs:enumeration value="hello"/> 
<xs:enumeration value="how do you do?"/> 
</xs:restriction> 
</xs:simpleType> 
       
<xs:simpleType name="restricted-greetings"> 
<xs:restriction base="greetings"> 
<xs:whiteSpace value="collapse"/> 
</xs:restriction> 
</xs:simpleType> 
  
greetings类型可以接受how do you do?,但会拒绝how do     you do?,因为他没有出现在enumeration中。但restricted-greetings则可以接受后者,因为通过whiteSpace facet,他可以在Lexical Space之前先对how do     you do?进行空格折叠,而变成enumeration 中的how do you do?。 
  
e)        定义了固定属性的facet 
除了enumeration和pattern之外,其他所有的facet都有一个“fixed”属性。当该属性的值为true时,子类型将不能再修改该facet的值。  
 
  |