posts - 431,  comments - 344,  trackbacks - 0

 

对一组值的约束(使用枚举)
下述案例给名为"car"的元素定义了约束条件,符合条件的值有:Audi、Golf、BMW:
<xs:element name="car">

<xs:simpleType>
 <xs:restriction base="xs:string">
    <xs:enumeration value="Audi"/>
    <xs:enumeration value="Golf"/>
    <xs:enumeration value="BMW"/>
 </xs:restriction>
</xs:simpleType>

</xs:element>  

对一系列值的约束 

下述案例给名为"letter"的元素定义了约束条件。唯一符合条件的值是从 a 到 z 之间的一个小写字母:

<xs:element name="letter">

<xs:simpleType>

<xs:restriction base="xs:string">

<xs:pattern value="[a-z]"/>

</xs:restriction>

</xs:simpleType>

</xs:element>

下述案例给名为"gender"的元素定义了一个约束条件。唯一符合的值是male (男性)或female(女性):

<xs:element name="gender">

<xs:simpleType>

<xs:restriction base="xs:string">

<xs:pattern value="male|female"/>

</xs:restriction>

</xs:simpleType>

</xs:element>

对空白符的约束

下述案例给名为"address"的元素定义了一个约束条件。空白符设置为"preserve"(保留),这意味着XML处理器不会删除任何空白符:

<xs:element name="address">

<xs:simpleType>

<xs:restriction base="xs:string">

<xs:whiteSpace value="preserve"/>

</xs:restriction>

</xs:simpleType>

</xs:element>

下述案例给名为"address"的元素定义了一个约束条件。空白符设置为" replace "(替代),这意味着XML处理器会用空格替代所有的空白字符(其中包括:换行符、制表符、空格符、回车符):

<xs:element name="address">

<xs:simpleType>

<xs:restriction base="xs:string">

<xs:whiteSpace value="replace"/>

</xs:restriction>

</xs:simpleType>

</xs:element>

下述案例给名为"address"的元素定义了一个约束条件。空白符设置为"collapse"(清除),这意味着XML处理器会清除所有的空白字符(换行符、制表符、空格符以及回车符都被空格符替代。头部、尾部的空格会被清除,多个空格也会自动减少为一个):

<xs:element name="address">

<xs:simpleType>

<xs:restriction base="xs:string">

<xs:whiteSpace value="collapse"/>

</xs:restriction>

</xs:simpleType>

</xs:element>

对数据类型的约束

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
指定了允许出现的小数位数的最大位数。值必须大于等于0

length

Specifies the exact number of characters or list items allowed. Must be equal to or greater than zero
指定了允许出现的字符或列表项的个数。值必须大于等于0

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
指定了允许出现的字符或列表项的最大个数。值必须大于等于0

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
指定了允许出现的字符或列表的最小个数。值必须大于等于0

pattern

Defines the exact sequence of characters that are acceptable
定义了符合要求的字符的精确排列顺序

totalDigits

Specifies the exact number of digits allowed. Must be greater than zero
指定了允许出现的字符的精确个数。值必须大于0

whiteSpace

Specifies how white space (line feeds, tabs, spaces, and carriage returns) is handled
指定了空白符的处理方式(其中包括:换行符、制表符、空格符和回车符)

posted on 2008-03-29 12:44 周锐 阅读(847) 评论(0)  编辑  收藏 所属分类: JavaXML

只有注册用户登录后才能发表评论。


网站导航: