XML Schema规范共推荐12种约束。
范围约束 | minInclusice、manInclusice、minExclusive、maxExcusive |
长度约束 | length、minLength、maxLength |
精度约束 | fractionDigits、totalDigits |
枚举约束 | enumeration |
正则表达式约束 | pattern |
空白处理 | whiteSpace |
fractionDigits:用于定义十进制数小数部分的精度。
totalDigits:用于指定decimal及其派生类型的数值精度。
whiteSpace:指定字符串中空白的处理方式,preserve(保留空白)、replace(字符串中Newline、tab和carriage-return都会被替换成空白)、collapse(字符串中Newline、tab和carriage-return都会被替换成空白,并且字符串中间连续的空白会被压缩成一个,字符串前后的空白会被自动删除)。
约束的使用方式:
<xs:facet value="option" />
Table B1.a. Simple Types & Applicable Facets | ||||||
---|---|---|---|---|---|---|
Simple Types | Facets | |||||
length | minLength | maxLength | pattern | enumeration | whiteSpace | |
string | y | y | y | y | y | y |
normalizedString | y | y | y | y | y | y |
token | y | y | y | y | y | see (1) |
base64Binary | y | y | y | y | y | see (1) |
hexBinary | y | y | y | y | y | see (1) |
integer | y | y | see (1) | |||
positiveInteger | y | y | see (1) | |||
negativeInteger | y | y | see (1) | |||
nonNegativeInteger | y | y | see (1) | |||
nonPositiveInteger | y | y | see (1) | |||
long | y | y | see (1) | |||
unsignedLong | y | y | see (1) | |||
int | y | y | see (1) | |||
unsignedInt | y | y | see (1) | |||
short | y |