前端之家收集整理的这篇文章主要介绍了
xml 指定约束文件,
前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
一. 使用schemaLocation:
@H_
403_4@辅助xmlns引入“实”的命名空间,指定具体的命名空间所指向的
文件,需要具体路径。2部分组成:
定义好的命名空间路径 + 具体schema文件的路径
@H_
403_4@参考:
http://www.jb51.cc/article/p-hfddcuuj-gq.html
@H_
403_4@book.xml
<?xml version="1.0" encoding="UTF-8"?>
<书架 xmlns="http://www.example.org/NewXMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation = "http://www.example.org/NewXMLSchema ../xsd/A.xsd">
<书>
<书名>XML基础</书名>
<作者>SAM-SHO</作者>
<售价>28.00元</售价>
<出版时间>12</出版时间>
<数量>154</数量>
<出版年限>123</出版年限>
</书>
</书架>
@H_
403_4@A.xsd
<?xml version="1.0" encoding="UTF-8"?>
<schema xmlns="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.example.org/NewXMLSchema"
xmlns:tns="http://www.example.org/NewXMLSchema"
elementFormDefault="qualified">
<element name="书架"> <!--声明<书架>元素-->
<complexType><!--声明<书架>元素为复杂类型-->
<sequence maxOccurs="unbounded"><!--声明<书架>元素 sequence-有顺序; maxOccurs-无上限-->
<element name="书"><!--声明<书>元素-->
<complexType>
<sequence>
<element name="书名" type="string"></element><!--声明<书名>等元素的类型为string-->
<element name="作者" type="string"></element>
<element name="售价" type="string"></element>
<element name="出版时间" type="string"></element>
<element name="数量" type="integer"></element>
<element name="出版年限" type="int"></element>
</sequence>
</complexType>
</element>
</sequence>
</complexType>
</element>
</schema>
二. 使用 eclipse 引入xsd