xml-schema仅含有文本及案例
来源:互联网 发布:自动排料软件 编辑:程序博客网 时间:2024/06/05 06:02
<!--Schema-仅含有文本-->
案例
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.example.org/text"
xmlns:tns="http://www.example.org/text"
elementFormDefault="qualified">
<!-- xmlschema仅含有文本 -->
<xs:element name="books">
<xs:complexType>
<xs:sequence>
<xs:element name="book">
<xs:complexType>
<xs:sequence>
<xs:element name="name">
<!-- 简单的类型即可 -->
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:pattern value="[a-z]{9}"></xs:pattern>
</xs:restriction>
</xs:simpleType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
被约束文件
<?xml version="1.0" encoding="UTF-8"?>
<books xmlns="http://www.example.org/text" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.example.org/text text.xsd">
<book>
<name>aaaaaaaaa</name>
</book>
</books>
案例2:
<!--混合类型-无序->
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.example.org/text"
xmlns:tns="http://www.example.org/text"
elementFormDefault="qualified">
<!-- xmlschema仅含有文本 -->
<xs:element name="books">
<xs:complexType>
<xs:sequence>
<xs:element name="book">
<!-- mixed=true代表是混合类型的-->
<xs:complexType mixed="true">
<!--代表无序-->
<xs:all>
<xs:element name="name" maxOccurs="1">
<!-- 简单的类型即可 -->
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:pattern value="[a-z]{9}"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="price" type="xs:double"/>
</xs:all>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
无序
<?xml version="1.0" encoding="UTF-8"?>
<books xmlns="http://www.example.org/text" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.example.org/text text1.xsd">
<book>
<!-- all代表的是无序的 -->
<price>12.9</price>
<name>xxxxxxxxx</name>
</book>
</books>
案例3:
<!--互斥-->
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.example.org/text"
xmlns:tns="http://www.example.org/text"
elementFormDefault="qualified">
<!-- xmlschema仅含有文本 -->
<xs:element name="books">
<xs:complexType>
<xs:sequence>
<xs:element name="book">
<!-- mixed=true代表是混合类型的-->
<xs:complexType mixed="true">
<!-- choice代表的是互斥的 -->
<xs:choice>
<xs:element name="name" maxOccurs="1">
<!-- 简单的类型即可 -->
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:pattern value="[a-z]{9}"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="price" type="xs:double"/>
</xs:choice>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
被约束文件
<?xml version="1.0" encoding="UTF-8"?>
<books xmlns="http://www.example.org/text" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.example.org/text text3.xsd">
<book>
<!-- choice代表的是互斥的 -->
<price>12.9</price>
</book>
</books>
案例4
<!--schema--->
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.example.org/text"
xmlns:tns="http://www.example.org/text"
elementFormDefault="qualified">
<!-- xmlschema仅含有文本 -->
<xs:element name="books">
<xs:complexType>
<xs:sequence>
<xs:element name="book">
<!-- mixed=true代表是混合类型的-->
<xs:complexType mixed="true">
<!-- sequence代表的是有序的 -->
<xs:sequence>
<xs:element name="name" maxOccurs="5">
<!-- 简单的类型即可 -->
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:pattern value="[a-z]{9}"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="price" type="xs:double" minOccurs="2" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
被约束文件
<?xml version="1.0" encoding="UTF-8"?>
<books xmlns="http://www.example.org/text" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.example.org/text text4.xsd">
<book>
<!-- sequence代表的是有序的 -->
<name>xxxxxxxxx</name>
<name>xxxxxxxxx</name>
<name>xxxxxxxxx</name>
<name>xxxxxxxxx</name>
<name>xxxxxxxxx</name>
<price>12.9</price>
<price>12.9</price>
<price>12.9</price>
<price>12.9</price>
<price>12.9</price>
<price>12.9</price>
<price>12.9</price>
<price>12.9</price>
<price>12.9</price>
<price>12.9</price>
</book>
</books>
案例5
<!--定义组-有序单个->
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.example.org/text"
xmlns:tns="http://www.example.org/text"
xmlns="http://www.example.org/text"
elementFormDefault="qualified">
<!-- 定义组 -->
<xs:group name="bookGroup">
<xs:sequence>
<xs:element name="name" type="xs:string"/>
<xs:element name="price" type="xs:double"/>
<xs:element name="cdata" type="xs:date"/>
</xs:sequence>
</xs:group>
<xs:element name="books">
<xs:complexType>
<xs:sequence>
<xs:element name="book">
<xs:complexType>
<xs:sequence>
<!-- 引用组 -->
<xs:group ref="bookGroup"/>
<xs:element name="author" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
被约束文件
<?xml version="1.0" encoding="UTF-8"?>
<books xmlns="http://www.example.org/text" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.example.org/text text5.xsd">
<book>
<!-- group代表的是有序的 -->
<name>xxxxxxxxx</name>
<price>12.9</price>
<cdata>2010-10-10</cdata>
<author>chenhj</author>
</book>
</books>
案例6
<!--定义组-无序、多个->
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.example.org/text" xmlns:tns="http://www.example.org/text"
xmlns="http://www.example.org/text" elementFormDefault="qualified">
<!-- 定义组 -->
<xs:group name="bookGroup">
<xs:choice>
<xs:element name="name" type="xs:string" />
<xs:element name="price" type="xs:string" />
<xs:element name="cdata" type="xs:string" />
</xs:choice>
</xs:group>
<xs:element name="books">
<xs:complexType>
<xs:all>
<xs:element name="book">
<xs:complexType>
<xs:sequence>
<!-- 引用组 -->
<xs:group ref="bookGroup" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:all>
</xs:complexType>
</xs:element>
</xs:schema>
被约束文件
<?xml version="1.0" encoding="UTF-8"?>
<books xmlns="http://www.example.org/text"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.example.org/text text6.xsd">
<book>
<!-- group代表的是有序的 -->
<!-- 无序,多次 -->
<name>xxxxxxxxx</name>
<cdata>2</cdata>
<price>2</price>
<price>2</price>
<price>2</price>
<price>2</price>
<price>2</price>
<price>2</price>
<price>2</price>
</book>
</books>
- xml-schema仅含有文本及案例
- xml-schema空元素约束及案例
- xml-schema小案例
- XML简介之Schema之 XSD 仅含文本复合元素 VS XSD 带有混合内容的复合类型
- Schema案例
- schema案例
- 文本挖掘过程及案例
- XML Schema 配置文件自动生成c#类设计案例子
- XML Schema术语及样例
- xml之数据解析及schema解析
- Xml Schema学习例子及命名空间
- XML简介之Schema之XSD 复合空元素 VS XSD 复合类型 - 仅含元素
- xml基础及解析案例
- XML Schema
- XML Schema
- XML Schema
- xml schema
- XML Schema
- 关于Unity3D中的UnitySendMessage方法的使用!!!
- java中的matches()方法
- 开始了
- 一对多hibernate 添加数据(二)
- iis问题
- xml-schema仅含有文本及案例
- FileChannel的用法
- 在Ubuntu上为Android增加硬件抽象层(HAL)模块访问Linux内核驱动程序
- memcached介绍及原理
- CGI的基本原理
- uva--10474+水题
- 通过ApplicationContextAware获取bean
- xml-schema空元素约束及案例
- 《算法竞赛入门经典(第2版)》代码 Chapter 3