schema约束
Posted selfdef
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了schema约束相关的知识,希望对你有一定的参考价值。
schema约束
1.xsd
<?xml version="1.0" encoding="UTF-8"?>
<schema xmlns="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.example.org/1" //引入约束文件使用这个 url地址
xmlns:tns="http://www.example.org/1" //约束文件
elementFormDefault="qualified">
//上面的东西eclipse会帮忙生成好
<element name = "person">
<complexType>
<sequence> //表示元素出现的顺序
//简单元素 写在这三个标签内
<element name="name" type="string"></element>
<element name="age" type="int"></element>
</sequence>
</complexType>
</element>
</schema>
person.xml
<person xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" //表示这是一个被约束的文件
xmlns="http://www.example.org/1" // 约束文档中的targetNameSpace
xsi:schemaLocation="http://www.example.org/1 1.xsd">
//targetNameSpace 空格 约束文档的地址路径(名称)
schema约束
// 对标签进行约束
<complexType>: 使用复杂元素进行包裹
<sequence>: 表示元素出现的顺序 maxOccurs="unbounded" 表示不限出现次数(在sequence下)
<all>: 元素只能出现一次
<choice>: 元素进行选择
<any>:任意元素
//对属性进行约束
<attribute name="id1" type="int" use="required"></attribute> //表示必须要出现一个叫做id1 的 int类型的属性要写在</complexType>前面
以上是关于schema约束的主要内容,如果未能解决你的问题,请参考以下文章