笔记 ------XML Schema验证

<?xml version="1.0" encoding="UTF-8"?>
<book-list xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="books.xsd">
	<book>
		<name/>
		<author/>
		<price>1.01</price>
		<booktype>游戏攻略</booktype>
	</book>
	
	<book>
		<price>1.01</price>
		<name/>
		<author/>
		
		<booktype>游戏攻略</booktype>
	</book>
</book-list>







schema文件:
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="unqualified">
	 
	 <xs:element name="book-list" type="booklist-type"/>
	 <xs:complexType name="booklist-type">
		  <xs:all minOccurs="1" maxOccurs="unbounded">
		  	 <xs:element ref="book"/>
		  </xs:all>
	 </xs:complexType>
	 
	 
	 <xs:element name="book" type="book-type"/>
	 <!-- 构建book元素下的 子元素之间的层次关系 -->
	  <xs:complexType name="book-type">
	  	    <!-- 当前下子元素 在xml文档中必需顺序出现 
			<xs:sequence>
				<xs:element ref="name" />
				<xs:element ref="author"/>
				<xs:element ref="price"/>
				<xs:element ref="booktype"/>
			</xs:sequence> -->
			
			<xs:all>
				<xs:element ref="name" />
				<xs:element ref="author"/>
				<xs:element ref="price"/>
				<xs:element ref="booktype"/>
			</xs:all>
	  </xs:complexType>
	 
	 
	 <xs:element name="name" type="xs:string"/> 
	 <xs:element name="price" type="price-type"/>
	 <!-- 定义单价扩展数据类型 -->
	 <xs:simpleType name="price-type">
			<xs:restriction base="xs:decimal">
				 <!-- 限定当前价格最小值 -->
				 <xs:minExclusive value="0"/>
				 <!--限定价格的精度 -->
				 <xs:fractionDigits value="2"/>
			</xs:restriction>
		</xs:simpleType>
		 
	 <xs:element name="author" type="xs:string"/>
	 
	 <xs:element name="booktype" type="enun-type"/>
	 
	 <xs:simpleType name="enun-type">
			<xs:restriction base="xs:string">
				<xs:enumeration value="计算机编程"/>
				<xs:enumeration value="游戏攻略"/>
				<xs:enumeration value="恋爱高手"/>
			</xs:restriction>
		</xs:simpleType>
</xs:schema>

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值