您的位置:首页 > 其它

SCHEMA学习一

2016-02-03 14:27 357 查看
<!--定义简易元素-->
<xs:element name="lastname" type="xs:string"/>
<xs:element name="age" type="xs:integer"/>

<lastname>Smith</lastname>
<age>28</age>

<!--简易元素的默认值和固定值-->
<xs:element name="color" type="xs:string" default="red"/>
<xs:element name="color" type="xs:string" fixed="red"/>

<!--属性。简易元素无法拥有属性-->
<xs:attribute name="width" type="xs:decimal"/>
<width>10.2</width>

<!--属性的默认值和固定值-->
<xs:attribute name="width" type="xs:decimal" default="10.1"/>
<xs:attribute name="width" type="xs:decimal" fixed="10.1"/>

<!--必选的属性 使用use属性-->
<xs:attribute name="lang" type="xs:string" use="required"/>

<!--对值的限定。如下定义了带有一个限定且名为age的元素,
age的值不能低于0或者高于120-->
<xs:element name="age">
<xs:simpleType>
<xs:restriction base="xs:integer">
<xs:minInclusive value="0"/>
<xs:maxInclusive value="120"/>
</xs:restriction>
</xs:simpleType>
</xs:element>

<!--对一组值的限定 使用枚举约束 enumeration constraint-->
<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>

<!--对一系列值的限定 使用pattern constriction 只能输入a到z中的一个-->
<xs:element name="letter">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:pattern value="[a-z]"/>
</xs:restriction>
</xs:simpleType>
</xs:element>

<!--对空白字符 使用whiteSpace限定
preserve表示XML不会移除任何空白字符
replace表示移除任何回车 换行制表符空格等空白字符
collpase表示换行回车空格及制表符被替换为空格 开头和结尾的空格会被移除 而多个连续的空格会被缩减为一个单一的空格-->
<xs:element name="address">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:whiteSpace value="preserve"/>
</xs:restriction>
</xs:simpleType>
</xs:element>

<!--对长度的限定 限定password长度为8个字符-->
<xs:element name="password">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:length value="8"/>
<xs:minLength value="5"/>
<xs:maxLength value="10"/>
</xs:restriction>
</xs:simpleType>
</xs:element>

<!-- 数据类型的限定
enumeration 定义可接受值的一个列表
fractionDigits 定义所允许的最大的小数位数
length 定义所允许的字符或者列表项目的精确数目
maxExclusive 定义数值的上限 所允许的值必须小于此值
maxInclusive 定义数值的上限 所允许的值必须小于等于此值
maxLength 定义所允许的字符或者列表项目的最大数目
minExclusive 定义数值的下限
minInclusive 定义数值的下限
minLength 定义所允许的字符或者列表项目的最小数目
pattern 定义可接受的字符的精确序列
totalDigits 定义所允许的阿拉伯数字的精确位数
whiteSpace 定义空白字符的处理方式
-->
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: