一、 element::声明一个元素。
1、 声明方式:
<element
abstract = Boolean : false
block = (#all | List of (extension | restriction | substitution))
default = string
final = (#all | List of (extension | restriction))
fixed = string
form = (qualified | unqualified)
id = ID
maxOccurs = (nonNegativeInteger | unbounded) : 1
minOccurs = nonNegativeInteger : 1
name = NCName
nillable = Boolean : false
ref = QName
substitutionGroup = QName
type = QName
{any attributes with non-schema Namespace}...>
Content: (annotation?, ((simpleType | complexType)?, (unique | key | keyref)*))
</element>
2、 block:
导出类型,该元素是为了防止具有指定导出类型的元素被用于替代该元素。其值可能为:
extension: 防止通过扩展导出的元素替换该元素。
restriction: 防止通过限制导出的元素替换该元素。
substitution:防止通过替换导出的元素替换该元素。
#all:防止所有的类型的导出元素替换该元素。
3、 default:
如果该元素为简单类型或者为textOnly的话,设置该元素的缺省值。default与fixed冲突。substitutionGroup:可用来替换该元素的元素的名称。该元素必须具有相同的类型后者具有从指定元素导出的类型。
如果引用的元素是在全局级别声明的(父元素是 schema 元素),则可以在任何元素上使用该属性。
类似与程序设计中的缺省值。
该值必须是 QName。
4、 final:
导出类型。可以为extension,restriction以及#all,仅仅作用于包含元素为schema的元素。
5、 fixed:
如果该元素是简单的或者为textOnly的元素的话,那么它的值是预定的不可更改的,可以使用fixed设置这个值,。fixed与default矛盾。它类似于程序设计中的const的作用。
6、 form:
元素的形式,是否通过命名空间前缀的限定。可选值有qualified与unqualified
7、 id
8、 maxOccurse、minOccurse
最多最少出现的次数。最大值为无限制”unbounded”,包含元素为”schema”的元素则自动禁止。
9、 name:
名称,为无冒号名称(NCName),如果包含元素为”Schema”的话,则必须具有。
10、 nillable:
显示指示是否可以付空值给这个元素。默认为false
11、 ref:
在此架构声明的元素,这个名称必须为该Schema中另一个Element的QName。如果包含元素为schema,则自动禁止。complexType、simpleType、key、keyref 和 unique 元素以及 nillable、default、fixed、form、block 和 type 属性不能出现。
12、 type:
该元素的数据类型,可以为内置类型以及simplyType、complexType的名称,type与ref不能够同时出现。
13、 元素信息:
出现次数:定义
父元素:schema、choice、all、sequence
内容:simplyType、complexType、key、keyRef、unique
14、 备注:
只有在 ref 和 type 属性均不存在时,simpleType 或 complexType 元素才可以作为子元素存在。此外,元素可以通过在 choice、all、sequence 和 complexType 元素内的引用出现。头元素声明必须直接定义复杂类型。
二、 Attribute:声明一个属性。
1、 声明方式:
<attribute
default = string
fixed = string
form = (qualified | unqualified)
id = ID
name = NCName
ref = QName
type = QName
use = (optional | prohibited | required): optional
{any attributes with non-schema Namespace...}>
Content: (annotation, (simpleType))
</attribute>
其中的部分属性说明:
2、 use:
一个指示符,指示如何使用该元素。可选值如下:
3、 optional:
属性可选的,并且可以具备任何值,这是默认值。
4、 prohibited:
不能够使用该属性,该属性用于其他复杂类型的限制中以禁止使用现有属性。也就是说它仅仅可以出现在restriction下面的属性中。
5、 required:
属性必须出现一次,可以使用该属性声明数据类型中的任何值。它的使用方法同prohibition,如果该属性声明为全局属性(其父元素为schema)的话,则该框架中的所有元素都需要该属性。
6、 元素信息
出现次数: 在 schema 元素中定义一次。在复杂类型或属性组中引用多次。
父元素: attributeGroup、schema、complexType、restriction (simpleContent)、extension (simpleContent)、restriction (complexContent)、extension (complexContent)
内容:annotation、simpleType
三、 attributeGroup:将一组属性声明归为一组,以便为复杂类型定义将它们并为一个组。
1、 声明方式:
<attributeGroup
id = ID
name = NCName
ref = QName
{any attributes with non-schema Namespace...}>
Content: (annotation?), ((attribute | attributeGroup)*, anyAttribute?))
</attributeGroup>
2、 元素信息:
出现次数: 无限制
父元素: attributeGroup、complexType、schema、restriction (simpleContent)、extension (simpleContent)、restriction (complexContent)、extension (complexContent)
内容: annotation、attribute、attributeGroup、anyAttribute
四、 anyAttribute:使来自指定命名空间的任何属性可以显示在包含 complexType 元素或包含 attributeGroup 元素中。
1、 声明方式:
<anyAttribute
id = ID
namespace = ((##any | ##other) | List of (anyURI | (##targetNamespace | ##local))) : ##any
processContents = (lax | skip | strict): strict
{any attributes with non-schema Namespace...}>
Content: (annotation?)
</anyAttribute>
部分属性说明如下:
2、 processContents :
一个指示器,指示应用程序或 XML 处理器应如何根据由该 anyAttribute 元素指定的属性处理 XML 文档的验证。
如果没有指定 processContents 属性,则默认为 strict。如果指定了 processContents,它必须是以下值之一。
Strict: XML处理器必须获得所需命名空间的架构,并且必须验证来自这些命名空间的所有属性。
Lax:XML处理器尝试获取所需命名空间的架构,并尝试验证来自这些命名空间的所有属性;但是,即使不能获取该架构,也不会发生任何错误。
Skip: XML 处理器不尝试验证来自指定命名空间的任何属性。
3、 元素信息:
出现次数 无限制
父元素 complexType、restriction (simpleContent)、extension (simpleContent)、restriction (complexContent)、extension (complexContent)、attributeGroup
内容 annotation
五、 simplyType:定义一个简单类型,它确定具有纯文本属性或者元素的值有关的信息以及对它们的约束。
1、 声明方式:
<simpleType
final = (#all | (list | union | restriction))
id = ID
name = NCName
{any attributes with non-schema Namespace}...>
Content: (annotation?, (restriction | list | union))
</simpleType>
2、 元素信息
出现次数 无限制
父元素 attribute、element、list、restriction (simpleType)、schema、union
内容 annotation、list、restriction (simpleType)、union
六、 complexType:定义一个复杂内容的元素,它确定属性集及元素内容。
1、 声明方式:
<complexType
abstract = Boolean : false
block = (#all | List of (extension | restriction))
final = (#all | List of (extension | restriction))
id = ID
mixed = Boolean : false
name = NCName
{any attributes with non-schema Namespace...}>
Content: (annotation?, (simpleContent | complexContent | ((group | all |
choice | sequence)?, ((attribute | attributeGroup)*, anyAttribute?))))
</complexType>
部分属性说明如下:
2、 mixed :
一个指示符,指示是否允许字符数据出现在该复杂类型的子元素之间。默认值为 false。
如果 simpleContent 元素是子元素,则不允许 mixed 属性。
如果 complexContent 元素是子元素,则该 mixed 元素可被 complexContent 元素的 mixed 属性重写。
可选。 ????
3、 元素信息:
出现次数 在架构内为无限制;在元素内为一次。
父元素 element、redefine、schema
内容 annotation、simpleContent、complexContent、group、all、choice、sequence、attribute、attributeGroup、anyAttribute
4、 备注:
复杂类型实质上是对可以包含属性和元素的元素的类型定义。一个元素可以由引用 complexType 元素(定义该元素的结构、内容和属性)的 type 属性声明。(一个元素还可以在其 type 属性中接受对 simpleType 的引用。)
一个复杂类型可以包含以下元素中的一个元素且只能包含一个元素,该元素确定在复杂类型中允许的内容类型。
simpleContent 该复杂类型具有字符数据或将 simpleType 作为内容并且不包含任何元素,但可以包含属性。
complexContent 该复杂类型只包含元素或不包含任何元素内容(空)。
group 该复杂类型包含在引用组中定义的元素。
sequence 该复杂类型包含在指定序列中定义的元素。
choice 该复杂类型允许在选项元素中指定的元素之一。
all 该复杂类型允许在所有元素中指定的任意或所有元素出现一次。
如果 group、sequence、choice 或 all 被指定为子元素,则可以选择使用以下元素声明 complexType 的属性。
attribute 该复杂类型包含指定的属性。
attributeGroup 该复杂类型包含在引用的 attributeGroup 中定义的属性。
anyAttribute 该复杂类型可以包含来自指定命名空间的任何属性。
可以使用任何数目的 attribute 或 attributeGroup 元素。还可以使用 anyAttribute 的一个实例。
如果指定 group、sequence、choice 或 all,则元素必须按以下顺序出现。
group | sequence | choice | all
attribute | attributeGroup
anyAttribute
七、 simplyContent:包含对 complexType 元素(它以字符数据或 simpleType 元素为内容)的扩展或限制并且不包含任何元素。
1、 声明方式:
<simpleContent
id = ID
{any attributes with non-schema Namespace}...>
Content: (annotation?, (restriction | extension))
</simpleContent>
八、 complexContent:包含对仅包含混合内容或元素的复杂类型的扩展或限制。
1、 声明方式:
<complexContent
id = ID
mixed = Boolean
{any attributes with non-schema Namespace}...>
Content: (annotation?, (restriction | extension))
</complexContent>
2、 元素信息:
出现次数 一次
父元素 complexType
内容 可选。annotation
必选。以下元素中的一个且只能是一个:restriction (complexContent) 或 extension (complexContent)。
元素集合方式元素声明:
九、 all:允许组中的元素以任意元素显示(或不显示在)在包含元素中。
1、 声明方式:
<all
id = ID
maxOccurs= 1: 1
minOccurs= (0 | 1): 1
{any attributes with non-schema Namespace...}>
Content: (annotation?, element*)
</all>
十、 sequence:要求组中的元素以指定的顺序出现在包含元素中
1、 声明方式:
<sequence
id = ID
maxOccurs = (nonNegativeInteger | unbounded) : 1
minOccurs = nonNegativeInteger : 1
{any attributes with non-schema Namespace}...>
Content: (annotation?, (element | group | choice | sequence | any)*)
</sequence>
2、 元素信息:
出现次数: 在组内为一次;否则为无限制。
父元素: group、choice、sequence、complexType、restriction (simpleContent)、extension (simpleContent)、restriction (complexContent)、extension (complexContent)
内容: annotation、any、choice、element、group、sequence
十一、 choince:允许且仅允许选定组中包含的一个元素出现在包含元素中。
1、 声明方式:
<choice
id = ID
maxOccurs= (nonNegativeInteger | unbounded) : 1
minOccurs= nonNegativeInteger : 1
{any attributes with non-schema Namespace}...>
Content: (annotation?, (element | group | choice | sequence | any)*)
</choice>
2、 元素信息:
出现次数: 在 group 和 complexType 元素中为一次;其他为无限制。
父元素: group、choice、sequence、complexType、restriction (simpleContent)、extension (simpleContent)、restriction (complexContent)、extension (complexContent)
内容: annotation、any、choice、element、group、sequence
扩展元素说明:
十二、 extension(simplyContent):包含对 simpleContent 的扩展。通过添加指定属性、属性组或 anyAttribute,扩展了简单类型或具有简单 内容的复杂类型,类似程序设计中的继承。
1、 方式:
<extension
base = QName
id = ID
{any attributes with non-schema Namespace}...>
Content: (annotation?, ((attribute | attributeGroup)*, anyAttribute?))
</extension>
2、 信息:
出现次数: 一次
父元素: simpleContent
内容: annotation、attribute、attributeGroup、anyAttribute
十三、 extension(complexContent):包含对 complexContent 的扩展。
1、 声明方式:
<extension
base = QName
id = ID
{any attributes with non-schema Namespace}...>
Content: (annotation?, ((group | all | choice | sequence)?, ((attribute |
attributeGroup)*, anyAttribute?)))
</extension>
2、 元素信息:
出现次数: 一次
父元素: complexContent
内容: annotation、attribute、attributeGroup、anyAttribute、choice、all、sequence、group
约束元素列表:
十四、 restriction(simplyType):定义对 simpleType 定义的约束。
1、 方式:
<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>
十五、 restriction (simplyContent):定义对 simpleContent 定义的约束。
1、 声明方式:
<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)*)?,
((attribute | attributeGroup)*, anyAttribute?))
</restriction>
十六、 restriction(complexContent):定义对complexContent定义的约束。
1、 声明方式:
<restriction
base = QName
id = ID
{any attributes with non-schema Namespace}...>
Content: (annotation?, (group | all | choice | sequence)?, ((attribute |
attributeGroup)*, anyAttribute?))
</restriction>
简单类型内容类声明:
十七、 Union:定义多个 simpleType 定义的集合。
1、 声明方式:
<union
id = ID
memberTypes = List of QNames
{any attributes with non-schema Namespace}...>
Content: (annotation?, (simpleType*))
</union>
部分属性说明:
2、 memberTypes:
在该架构(或由指定的命名空间指示的其他架构)中定义的内置数据类型或 simpleType 元素的名称列表。包含 union 元素的 simpleType 元素是从 memberTypes 值指定的简单类型导出的。memberTypes 中的值必须是限定名 (QNames)。
对于简单类型联合定义,简单类型列表是 memberTypes(本身是简单类型的列表)的内容和 union 元素下每一子 simpleType 元素定义的联合。请参见本主题内下文中的第二个示例。memberTypes 属性与 list 元素的 itemType 属性相反,它与 list 元素的 simpleType 元素子元素是互相排斥的。
可选。
3、 元素信息
出现次数 一次
父元素 simpleType
内容 annotation、simpleType
4、 备注:
由Union确定的Simply的取值只能够为memberTypes中的类型列表。
十八、 List:定义单个 simpleType 定义的集合。
1、 声明方式:
<list
id = ID
itemType = QName
{any attributes with non-schema Namespace}...>
Content: (annotation?, (simpleType?))
</list>
部分属性说明:
2、 itemType:
在该架构(或由指定的命名空间指示的其他架构)中定义内置数据类型或 simpleType 元素的名称。包含 list 元素的 simpleType 元素是从 list 值指定的简单类型导出的。list 值必须是限定名 (QName)。对 simpleType 元素子元素和 itemType 属性的使用是互相排斥的。
如果内容包含 simpleType 元素则为不允许的。否则为必需的。
3、 元素信息
出现次数: 一次
父元素: simpleType
子元素: annotation、simpleType
4、 备注:
如果数据类型是从列表数据类型导出的,则可以使用以下约束方面。
length
maxLength
minLength
enumeration
pattern
whiteSpace
列表始终是由空白分隔的。例如,如果从诸如 "books" "magazine articles" "technical newspapers and business journals" 之类的三个枚举的简单类型导出一个列表,将生成由 8 个字符串 "books", "magazine", "articles", "technical", "newspapers", "and", "business", "journals" 组成的列表,而不是三个字符串的列表。
十九、 restriction:(参考约束元素列表)
批注相关元素
二十、 annotation:定义批注。
1、 声明方式:
<annotation
id = ID
{any attributes with non-schema Namespace}...>
Content: (appinfo | documentation)*
</annotation>
2、 元素信息
出现次数 在父元素中一次。
父元素 任何元素
内容 appinfo、documentation
3、 备注
批注可以包含 appinfo 元素(由应用程序使用的信息)和 documentation 元素(由用户读取或使用的注释或文本)。
二十一、 Appinfo:定 annotation 元素中将由应用程序使用的信息。
1、 声明方式:
<appinfo
source = anyURI>
Content: ({any})*
</appinfo>
部分属性说明:
2、 source
应用程序信息的源。源必须是 URI 引用。可选。
二十二、 Documentation:指定 annotation 元素中将由用户读取或使用的信息。
1、 声明方式:
<documentation>
source = anyURI
xml:lang = language
Content: ({any})*
</documentation>
属性说明:
2、 source
应用程序信息的源。源必须是 URI 引用。可选。
3、 xml:lang
在内容中使用的语言的指示符。
可选。
4、 元素信息
出现次数 无限制
父元素 annotation
内容 任何格式正确的 XML 内容。
唯一性、主键及其应用相关元素
二十三、 Key:指定属性或元素值(或一组值)必须是指定范围内的键。键的范围为实例文档中的包含 element。键意味着数据在指定范围内应是唯一的、非可零的和始终存在的。
1、 声明方式:
<key
id = ID
name = NCName
{any attributes with non-schema Namespace}...>
Content: (annotation?, (selector, field+))
</key>
部分属性说明:
2、 name:
key 元素的名称。该名称必须是在 XML 命名空间规范中定义的无冒号名称 (NCName)。
该名称在标识约束集中必须是唯一的。
必选。
3、 元素信息
出现次数 无限制
父元素 element
内容 annotation、field、selector
4、 备注:
key 元素必须按顺序包含以下元素。
selector :
selector 元素包含 XML 路径语言 (XPath) 表达式,它指定一个元素集,在其中由字段指定的值必须唯一。
必须有一个且只有一个 selector 元素。
Field:
每一个 field 元素均包含一个 XPath 表达式,它指定对于由 selector 元素指定的元素集而言必须唯一的值(属性或元素值)。
如果有多个 field 元素,则 field 元素的组合必须是唯一的。在此情况下,单个 field 元素的值对于选定元素不一定是唯一的,但所有字段的组合必须是唯一的。
必须有一个或多个 field 元素。
二十四、 Keyref:定属性或元素值(或一组值)与指定的 key 或 unique 元素的值相对应(为content中指定的元素的元素值引用refer对应的Key的值)。
1、 声明方式:
<keyref
id = ID
name = NCName
refer = QName
{any attributes with non-schema Namespace}...>
Content: (annotation?, (selector, field+))
</keyref>
部分属性说明
2、 name
keyref 元素的名称。该名称必须是在 XML 命名空间规范中定义的无冒号名称 (NCName)。
该名称在标识约束集中必须是唯一的。
必选。
3、 refer
在该架构(或由指定的命名空间指示的其他架构)中定义的 key 或 unique 元素的名称。ref 值必须是限定名 (QName)。类型可以包括命名空间前缀。
必选。
4、 元素信息
出现次数 一次
父元素 element
内容 annotation、field、selector
5、 备注
keyref 元素必须按顺序selector及field元素(具体说明同key及keyref的备注)。
二十五、 Unique:指定属性或元素值(或者属性或元素值的组合)在指定范围内必须是唯一的。该值必须唯一或为零。
1、 声明方式
<unique
id = ID
name = NCName
{any attributes with non-schema Namespace}...>
Content: (annotation?, (selector, field+))
</unique>
属性说明
2、 name
unique 元素的名称。该名称必须是在 XML 命名空间规范中定义的无冒号名称 (NCName)。
该名称在标识约束集中必须是唯一的。
必选。
3、 元素信息
出现次数 一次
父元素 element
内容 annotation、field、selector
4、 备注
unique 元素必须按顺序包含selector及field元素(具体说明同key及keyref的备注)。
二十六、 Selector:指定 XML 路径语言 (XPath) 表达式,该表达式为标识约束选择一组元素(unique、key 和 keyref 元素)。
1、 声明方式:
<selector
id = ID
xpath = a subset of XPath expression
{any attributes with non-schema Namespace}...>
Content: (annotation?)
</selector>
部分属性说明
2、 xpath
相对于所声明的元素的 XPath 表达式。该表达式标识标识约束应用于(所声明的元素)的子元素
必选。
3、 元素信息
出现次数 一次
父元素 key、keyref、unique
内容 annotation
二十七、 Field:指定 XML 路径语言 (XPath) 表达式,该表达式指定用来定义标识约束(unique、key 和 keyref 元素)的值。
1、 元素声明方式:
<field
id = ID
xpath = a subset of XPath expression
{any attributes with non-schema Namespace}...>
Content: (annotation?)
</field>
属性说明:
2、 xpath
相对于由标识约束的选择器选择的每一元素的 XPath 表达式。该表达式必须标识单个元素或属性(其内容或值用于该约束)。如果表达式标识一个元素,则该元素必须是简单类型。
必选。
3、 元素信息
出现次数: 一次
父元素: key、keyref、unique
内容: annotation
插入外界架构元素说明
二十八、 Import:标识其架构组件由包含架构所引用的命名空间。
1、 元素声明方式:
<import
id = ID
namespace = anyURI
schemaLocation = anyURI
{any attributes with non-schema Namespace}...>
Content: (annotation?)
</import>
部分属性说明
2、 namespace
对要导入的命名空间的 URI 引用。
namespace 属性指示包含架构文档可以包含对该命名空间中架构组件的限定的引用(通过用 xmlns 属性声明的一个或多个前缀)。
如果该属性不存在,则包含架构可以包含对导入的命名空间中各组件的非限定的引用。 可选。
3、 schemaLocation
对导入的命名空间的架构文档位置的 URI 引用。
如果该属性不存在,则作者允许该导入的命名空间的架构的标识由 XML 文档确定,该 XML 文档是包含架构的实例或者正处理它的用户或应用程序。
可选。
4、 元素信息
出现次数 无限制
父元素 schema
内容 annotation
5、 备注
include 元素和 import 元素之间的区别在于:import 元素允许引用来自目标命名空间不同的架构文档中的架构组件,而 include 元素则向包含架构中添加这样的架构组件,即目标命名空间相同的其他架构文档中的架构组件,或没有指定目标命名空间的其他架构文档中的架构组件。简言之,import 元素使您能够使用来自任何架构的架构组件;include 元素使您能够将所包括的架构的所有组件添加到包含架构中。
二十九、 Include:将指定的架构文档包含在包含架构的目标命名空间中。
1、 元素声明方式:
<include
id = ID
schemaLocation = anyURI
{any attributes with non-schema Namespace}...>
Content: (annotation?)
</include>
部分属性说明:
2、 schemaLocation
对包括在包含架构的目标命名空间的架构文档位置的 URI 引用。
必选。
3、 元素信息
出现次数 无限制
父元素 schema
子元素 annotation
4、备注
所包括的架构文档必须满足以下条件之一。
它必须具有与包含架构文档相同的目标命名空间。
它不得具有指定的目标命名空间(无 targetNamespace 属性)。
import 元素允许引用来自目标命名空间不同的架构文档中的架构组件,而 include 元素则向包含架构中添加这样的架构组件,即目标命名空间相同的其他架构文档中的架构组件,或没有指定目标命名空间的其他架构文档中的架构组件。简言之,import 元素使您能够使用来自任何架构的架构组件;include 元素使您能够将所包括的架构的所有组件添加到包含架构中。
其它元素说明
三十、 Group:将若干元素声明归为一组,以便将它们当作一个组并入复杂类型定义。
1、 元素声明方式:
<group
name= NCName
id = ID
maxOccurs = (nonNegativeInteger | unbounded) : 1
minOccurs = nonNegativeInteger : 1
name = NCName
ref = QName
{any attributes with non-schema Namespace}...>
Content: (annotation?, (all | choice | sequence))
</group>
部分属性说明:
2、 ref :
在该架构(或由指定的命名空间指示的其他架构)中声明的组的名称。ref 值必须是 QName。ref 可以包含命名空间前缀。
如果 ref 属性出现,则 id、minOccurs 和 maxOccurs 可以出现。Ref 和 name 是互相排斥的。
若要使用现有组定义声明一个组,请使用 ref 属性指定现有组定义。
<xs:group ref="globalGroup"/>
可选。
3、 元素信息
出现次数 无限制
父元素 schema、choice、sequence、complexType、restriction (complexContent)、extension (complexContent)
内容 annotation、all、choice、sequence
三十一、 redefine:允许在当前架构中重新定义从外部架构文件中获取的简单和复杂类型、组和属性组。
1、 声明方式:
<redefine
id = ID
schemaLocation = anyURI
{any attributes with non-schema Namespace}...>
Content: (annotation | (simpleType | complexType | group | attributeGroup))*
</redefine>
部分属性说明
2、 schemaLocation
对架构文档位置的 URI 引用。
必选。
3、 元素信息
出现次数 无限制
父元素 schema
内容 annotation、attributeGroup、complexType、group、simpleType
4、 备注
redefine 元素要求外部元素存在于和重新定义的架构相同的目标命名空间中。还可以使用 redefine 元素重新定义没有命名空间的架构并且重新定义的组件成为该架构的目标命名空间的一部分。
redefine 元素自身内的定义必须使用其当前定义作为基类型定义。属性组定义和模型组定义必须恰好包括一个对其自身的引用。不是重新定义的架构文档的所有定义都必须重新定义。
重新定义元素可能在基于重新定义的定义的其他类型定义上导致意外的结果,例如定义格式错误。
² XSD约束元素
一、 enumeration
指定的值的集合。这将数据类型约束为指定的值。
例如:
<xs:simpleType name="mountainbikesize">
<xs:restriction base="xs:string">
<xs:enumeration value="small"/>
<xs:enumeration value="medium"/>
<xs:enumeration value="large"/>
</xs:restriction>
</xs:simpleType>
二、 fractionDigits
在小数部分具有特定的最大小数位数的值。
三、 length
长度单位的数目。长度单位取决于数据类型。该值必须是 nonNegativeInteger。
四、 maxExclusive
上限值(所有值都小于该值)。该值的数据类型必须与继承的数据类型相同。
五、 maxInclusive
最大值。该值的数据类型必须与继承的数据类型相同。
六、 maxLength
长度单位的最大数目。长度单位取决于数据类型。该值必须是 nonNegativeInteger。
七、 minExclusive
下限值(所有值都大于该值)。该值的数据类型必须与继承的数据类型相同。
八、 minInclusive
最小值。该值的数据类型必须与继承的数据类型相同。
九、 minLength
长度单位的最小数目。长度单位取决于数据类型。该值必须是 nonNegativeInteger。
十、 pattern
数据类型的值必须匹配的特定模式。这将数据类型限制为与指定模式匹配的文本。模式值必须是正则表达式。
例子如下所示:
<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" >
<xs:element name="zips">
<xs:complexType>
<xs:sequence maxOccurs="unbounded">
<xs:element name="zip" type="better-us-zipcode"></xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:simpleType name="better-us-zipcode">
<xs:restriction base="xs:string">
<xs:pattern value="[0-9]{5}(-[0-9]{4})?"/>
</xs:restriction>
</xs:simpleType>
</xs:schema>
十一、 totalDigits
具有特定的最大小数位数的值。
十二、 whiteSpace
必须是 preserve、replace 或 collapse 之一的值。对于大多数数值型数据类型,不能更改 whiteSpace 方面。
1、 replace 出现的所有 #x9(制表符)、#xA(换行符)和 #xD(回车符)均由 #x20(空格)替代。
2、 collapse 在执行了由 replace 暗指的处理后,多个 #x20 的连续序列被压缩成单个 #x20,并且移除前导和结尾 #x20。
3、 collapse 在执行了由 replace 暗指的处理后,多个 #x20 的连续序列被压缩成单个 #x20,并且移除前导和结尾 #x20。