Schema的快速入门

1、首先编写XML数据文件  

<?xml version="1.0" encoding="UTF-8"?>
<books xmlns="http://www.example.org/book"       名称空间
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 声明是一个schema实例
xsi:schemaLocation="http://www.example.org/book book.xsd">   说明文件的约束位置
	<book>
		<name></name>
		<price>12</price>
	</book>
</books>

2、编写schema约束文档数据

<?xml version="1.0" encoding="UTF-8"?>
<schema xmlns="http://www.w3.org/2001/XMLSchema"   引用W3C中文档标准
targetNamespace="http://www.example.org/book"      目标名称空间,为其他文档引用提供方便
elementFormDefault="qualified">                    良好的格式   

<element name="books">
	<complexType>
		<sequence>
			<element name="book">
				<complexType>
					<sequence>
						<element name = "name" type = "string"></element>
						<element name = "price" type = "double"></element>
					</sequence>
				</complexType>
			</element>
		</sequence>
	</complexType>
</element>

</schema>
3、引用多个schema文件 

(1)、数据文件

<?xml version="1.0" encoding="UTF-8"?>
<company xmlns="http://www.example.org/company"
	xmlns:aa = "http://www.example.org/depatment"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://www.example.org/company company.xsd http://www.example.org/depatment depatment.xsd"
>
	<employee>
		<aa:name>人力资源</aa:name>
		<name>孔明</name>
	</employee>
</company>

(2)、约束文件

<?xml version="1.0" encoding="UTF-8"?>
<schema xmlns="http://www.w3.org/2001/XMLSchema"
 targetNamespace="http://www.example.org/company" 
 elementFormDefault="qualified">
 <element name="company">
 	<complexType>
 		<sequence>
			<element name="employee">
				<complexType>
					<sequence>
						<any></any>
						<element name = "name" type = "string"></element> 	
					</sequence>
				</complexType>
			</element>	
 		</sequence>
 	</complexType>
 </element>
</schema>

(3)约束文件2 

<?xml version="1.0" encoding="UTF-8"?>
<schema xmlns="http://www.w3.org/2001/XMLSchema"
 targetNamespace="http://www.example.org/depatment" 
 elementFormDefault="qualified">
 <element name="name" type="string"></element>
</schema>



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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值