xml element 约束

--默认值
<xs:element name="color" type="xs:string" default="red" />
--固定值
<xs:element name="color" type="xs:string" fixed="red" />
--必须输入
<xs:attribute name="xx" type="uu" use="required"/>

--限定值范围
<xs:element name="age">
<xs:simpletype >
<xs:restriction base="xs:integet">
   <xs:minInclusive value="0" />
   <xs:maxInclusive value="120" />
</xs:restriction>
</xs:smipletype>
<xs:element>

--限定为一组值
<xs:element name="car" type="cartype">
<xs:simpletype name="cartype">
   <xs:restriction base="xs:string">
    <xs:enumeration value="aaaa" />
    <xs:enumeration value="bbbb" />
    <xs:enumeration value="cccc" />
   </xs:restriction>
</xs:simpletype>
</xs:element>

--模式约束
<xs:element name="prodid">
<xs:simpletype>
<xs:restriction base="xs:integer">
   <xs:pattern value="[0-9][A-Z]" />
</xs:restriction>
</xs:simpletype>
</xs:element>

--小写字母+大写字母
<xs:element name="letter">
<xs:simpleType>
<xs:restriction base="xs:string">
    <xs:pattern value="([a-z][A-Z])+"/>
</xs:restriction>
</xs:simpleType>
</xs:element>

--male和female 只取其一 value 可以是正则表达式
<xs:element name="gender">
<xs:simpletype>
   <xs:restriction base="xs:string">
    <xs:pattern value="male|female" />
   </xs:restriction>
</xs:simpletype>
</xs:element>

---对空白字符的处理
<xs:element name="address">
<xs:simpletype>
   <xs:restriction base="xs:string">
    --这意味着 XML 处理器将移除所有空白字符
--    (换行、回车、空格以及制表符会被替换为空格,
--    开头和结尾的空格会被移除,而多个连续的空格
--    会被缩减为一个单一的空格):
    <xs:whiteSpace value="collapse" />
    --这意味着 XML 处理器将移除所有空白字符(换行、回车、空格以及制表符):
    <xs:whiteSpace value="replace"/>
    --XML 处理器不会移除任何空白字符
    <xs:whiteSpace value="preserve"/>
   </xs:restiction>
</xs:simpletype>
</xs:element>


--限定长度 8
<xs:element name="password">
<xs:simpleType>
<xs:restriction base="xs:string">
    <xs:length value="8"/>
</xs:restriction>
</xs:simpleType>
</xs:element>

--长度
<xs:element name="password">
<xs:simpleType>
<xs:restriction base="xs:string">
    <xs:minLength value="5"/>
    <xs:maxLength value="8"/>
</xs:restriction>
</xs:simpleType>
</xs:element>

 

限定描述
enumeration定义可接受值的一个列表
fractionDigits定义所允许的最大的小数位数。必须大于等于0。
length定义所允许的字符或者列表项目的精确数目。必须大于或等于0。
maxExclusive定义数值的上限。所允许的值必须小于此值。
maxInclusive定义数值的上限。所允许的值必须小于或等于此值。
maxLength定义所允许的字符或者列表项目的最大数目。必须大于或等于0。
minExclusive定义数值的下限。所允许的值必需大于此值。
minInclusive定义数值的下限。所允许的值必需大于或等于此值。
minLength定义所允许的字符或者列表项目的最小数目。必须大于或等于0。
pattern定义可接受的字符的精确序列。
totalDigits定义所允许的阿拉伯数字的精确位数。必须大于0。
whiteSpace定义空白字符(换行、回车、空格以及制表符)的处理方式。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值