xml的schema约束

编写的schema约束
<?xml version="1.0" encoding="utf-8"?> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.stella.cn" elementFormDefault="qualified"> <xs:element name="学生管理系统"> <xs:complexType> <xs:sequence maxOccurs="unbounded"> <xs:element name="学生"> <xs:complexType> <xs:sequence> <xs:element name="编号" type="xs:decimal"/> <xs:element name="姓名" type="xs:string"/> <xs:element name="性别" type="xs:string"/> <xs:element name="年龄" type="xs:integer"/> <xs:element name="密码" type="xs:string"/> </xs:sequence> <xs:attribute name="id" type="xs:integer" use="required"/> </xs:complexType> </xs:element> </xs:sequence> </xs:complexType> </xs:element> </xs:schema>

 以下是用到这个约束的xml

<?xml version="1.0" encoding="UTF-8"?>
<s:学生管理系统 xmlns:s="http://www.stella.cn"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.stella.cn student.xsd">
	<s:学生 id="1">
		<s:编号>
			89757
		</s:编号>
		<s:姓名>
			jack
		</s:姓名>
		<s:性别>
			女
		</s:性别>
		<s:年龄>
			18
		</s:年龄>
		<s:密码>
			789		
		</s:密码>
	</s:学生>
</s:学生管理系统>

  

posted @ 2014-04-02 21:26  lxricecream  阅读(188)  评论(0)    收藏  举报