java XML 约束

分为:

DTD约束

Schema约束:

    1.是基于DTD的替代者

    2.描述XML文档的结构

使用:

1.创建 XML schema File 文件

<?xml version="1.0" encoding="UTF-8"?>
<schema 
xmlns="http://www.w3.org/2001/XMLSchema" 
targetNamespace="http://www.hello.org/Product" 
xmlns:tns="http://www.hello.org/Product" 
elementFormDefault="qualified">
	<element name="product">
			<complexType>
				<sequence>
					<element name="id" type="int"/>
					<element name="name" type="string"/>
					<element name="price" type="float"/>
				</sequence>
			</complexType>
		</element>
</schema>

通常:xmlns="http://www.w3.org/2001/XMLSchema"-----标准,不改动

        targetNamespace="http://www.hello.org/Product------命名空间--对应约束的标签(“公司网址/创建schema文件的名称”)

        xmlns:tns="http://www.hello.org/Product" ----------默认命名空间
2.引用约束

 必须按照建立的约束的顺序、类型、个数进行引用

<?xml version="1.0" encoding="UTF-8"?>
<!-- 引用schame约束文件 -->

<product xmlns="http://www.hello.org/Product" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.hello.org/Product Product.xsd">
	<id>123</id>
	<name>af</name>
	<price>3.3</price>
</product>

xmlns="http://www.hello.org/Product" --------指定命名空间

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"--------标准
xsi:schemaLocation="http://www.hello.org/Product Product.xsd"> ----------第一个参数为命名空间、第二个参数为文件名称


                                   

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值