一、约束模式
二、好处
三、常用的约束模式语言
四、XMLDTD
五、schema
步骤:
1、创建.xsd
2、创建.xml
3、在.xml,引入.xsd,
4、修改root节点,把
<article></article>
改为自己的,并新增一条 xmlns="
http://www.tns.com"
<students
xmlns="http://www.tns.com" 新增
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.tns.com
file:///C:/Documents%20and%20Settings/xx/%e6%a1%8c%e9%9d%a2/%e7%bd%91%e9%a1%b5API/students.xsd">
内容
</students>
5、常用.xsd使用
//限定长nei度minlength、maxlength
<xs:element name="name" >
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:minLength value="2"/>
<xs:maxLength value="5" />
</xs:restriction>
</xs:simpleType>
</xs:element>
//限定范围,minInclusive和maxInclusive
<xs:element name="age">
<xs:simpleType>
<xs:restriction base="xs:integer">
<xs:minInclusive value="0" />
<xs:maxInclusive value="35"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
//限定输入取值,只能取‘男’‘女’
<xs:element name="sex">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:pattern value="['男'|'女']" />
</xs:restriction>
</xs:simpleType>
</xs:element>
//可接受的值是由 8 个字符组成的一行字符
<xs:element name="password">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:pattern value="[a-zA-Z0-9]{8}"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
六:参考代码: