xml学习总结(三)
复杂Schema
扩展包含简单内容的复杂类型
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified" attributeFormDefault="unqualified">
<!-- 定义一个book_Type类型 -->
<xs:complexType name="book_Type">
<xs:simpleContent>
<!-- 从token类型派生出book_Type类型 -->
<xs:extension base="xs:token">
<!-- 增加一个name属性 -->
<xs:attribute name="name" type="xs:token" use="required"/>
<!-- 增加一个isbn属性 -->
<xs:attribute name="isbn" use="required">
<!-- 使用simpleType子元素定义isbn属性的类型 -->
<xs:simpleType>
<xs:restriction base="xs:int">
<xs:totalDigits value="8"/>
</xs:restriction>
</xs:simpleType>
</xs:attribute>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
<!-- 定义一个extended_book_Type类型 -->
<xs:complexType name="extended_book_Type">
<xs:simpleContent>
<!-- 从book_Type类型派生出extended_book_Type类型 -->
<xs:extension base="book_Type">
<!-- 增加price属性 -->
<xs:attribute name="price" use="required">
<!-- 使用simpleType子元素定义price属性的类型 -->
<xs:simpleType>
<xs:restriction base="xs:decimal">
<xs:maxExclusive value="100"/>
<xs:minExclusive value="0"/>
<xs:fractionDigits value="2"/>
</xs:restriction>
</xs:simpleType>
</xs:attribute>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
<!-- 定义book元素,其类型是extended_book_Type -->
<xs:element name="book" type="extended_book_Type"/>
</xs:schema>
限制包含简单类型的复杂类型
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified" attributeFormDefault="unqualified">
<!-- 定义一个book_Type类型 -->
<xs:complexType name="book_Type">
<xs:simpleContent>
<xs:extension base="xs:token">
<xs:attribute name="name" type="xs:token" use="required"/>
<xs:attribute name="isbn">
<!-- 使用simpleType子元素定义isbn属性的类型 -->
<xs:simpleType>
<xs:restriction base="xs:int">
<xs:totalDigits value="8"/>
</xs:restriction>
</xs:simpleType>
</xs:attribute>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
<!-- 定义一个restricted_book_Type类型 -->
<xs:complexType name="restricted_book_Type">
<xs:simpleContent>
<xs:restriction base="book_Type">
<!-- 定义该元素的内容只能是如下枚举值之一 -->
<xs:enumeration value="疯狂Java体系"/>
<xs:enumeration value="疯狂Java实训教程"/>
<xs:attribute name="name" use="required">
<!-- 使用simpleType重新限定name属性的类型 -->
<xs:simpleType>
<xs:restriction base="xs:token">
<xs:maxLength value="14"/>
<xs:minLength value="4"/>
</xs:restriction>
</xs:simpleType>
</xs:attribute>
<!-- 删除原来的isbn属性 -->
<xs:attribute name="isbn" use="prohibited"/>
</xs:restriction>
</xs:simpleContent>
</xs:complexType>
<!-- 定义book元素,其类型是restricted_book_Type -->
<xs:element name="book" type="restricted_book_Type"/>
</xs:schema>
限制包含子元素的类型
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified" attributeFormDefault="unqualified">
<!-- 定义一个book_Type类型,该类型下包含2个有序子元素 -->
<xs:complexType name="book_Type">
<!-- 使用sequence定义2个子元素 -->
<xs:sequence>
<xs:element name="name" type="xs:token"/>
<!-- 如果派生类型想删除如下子元素,必须指定minOccurs="0" -->
<xs:element name="price" type="xs:decimal" minOccurs="0"/>
</xs:sequence>
<!-- 为该类型定义2个属性 -->
<xs:attribute name="isbn" type="xs:int"/>
<xs:attribute name="publish-date" type="xs:date"/>
</xs:complexType>
<!-- 定义restrict_book_Type类型 -->
<xs:complexType name="restrict_book_Type">
<xs:complexContent>
<!-- 通过限制book_Type类型派生新类型 -->
<xs:restriction base="book_Type">
<xs:sequence>
<!-- 为name元素的类型增加进一步约束 -->
<xs:element name="name">
<xs:simpleType>
<xs:restriction base="xs:token">
<xs:maxLength value="20"/>
<xs:minLength value="4"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<!-- 不再定义price元素,即可认为删除了该元素 -->
</xs:sequence>
<!-- 为publish-date属性的类型增加进一步约束 -->
<xs:attribute name="publish-date">
<xs:simpleType>
<xs:restriction base="xs:date">
<xs:maxExclusive value="2009-05-12"/>
<xs:minExclusive value="2007-05-12"/>
</xs:restriction>
</xs:simpleType>
</xs:attribute>
<!-- 删除isbn属性 -->
<xs:attribute name="isbn" use="prohibited"/>
</xs:restriction>
</xs:complexContent>
</xs:complexType>
<xs:element name="book" type="restrict_book_Type"/>
</xs:schema>
扩展包含子元素的类型
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified" attributeFormDefault="unqualified">
<!-- 定义一个book_Type类型,该类型下包含2个有序子元素 -->
<xs:complexType name="book_Type">
<!-- 使用sequence定义2个子元素 -->
<xs:sequence>
<xs:element name="name" type="xs:token"/>
<xs:element name="price" type="xs:decimal"/>
</xs:sequence>
<!-- 为该类型定义2个属性 -->
<xs:attribute name="isbn" type="xs:int"/>
<xs:attribute name="publish-date" type="xs:date"/>
</xs:complexType>
<!-- 定义extend_book_Type类型 -->
<xs:complexType name="extend_book_Type">
<xs:complexContent>
<!-- 通过扩展book_Type类型派生新类型 -->
<xs:extension base="book_Type">
<xs:sequence>
<!-- 新增定义2个子元素 -->
<xs:element name="type" type="xs:token"/>
<xs:element name="targetMarket" type="xs:token"/>
</xs:sequence>
<!-- 新增一个publish-house属性 -->
<xs:attribute name="publish-house" type="xs:token"/>
</xs:extension>
</xs:complexContent>
</xs:complexType>
<xs:element name="book" type="extend_book_Type"/>
</xs:schema>
限制混合内容类型
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified" attributeFormDefault="unqualified">
<!-- 定义一个book_Type类型,该类型下包含2个有序子元素,指定它是混合内容类型 -->
<xs:complexType name="book_Type" mixed="true">
<!-- 使用sequence定义2个子元素 -->
<xs:sequence>
<xs:element name="name" type="xs:token"/>
<!-- 如果派生类型想删除如下子元素,必须指定minOccurs="0" -->
<xs:element name="price" type="xs:decimal" minOccurs="0"/>
</xs:sequence>
<!-- 为该类型定义2个属性 -->
<xs:attribute name="isbn" type="xs:int"/>
<xs:attribute name="publish-date" type="xs:date"/>
</xs:complexType>
<!-- 定义mixed_book_Type类型,依然是混合内容类型 -->
<xs:complexType name="mixed_book_Type" mixed="true">
<xs:complexContent>
<!-- 通过限制book_Type类型派生新类型 -->
<xs:restriction base="book_Type">
<xs:sequence>
<!-- 为name元素的类型增加进一步约束 -->
<xs:element name="name">
<xs:simpleType>
<xs:restriction base="xs:token">
<xs:maxLength value="20"/>
<xs:minLength value="4"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<!-- 不再定义price元素,即可认为删除了该元素 -->
</xs:sequence>
<!-- 删除isbn属性 -->
<xs:attribute name="isbn" use="prohibited"/>
</xs:restriction>
</xs:complexContent>
</xs:complexType>
<!-- 定义restrict_book_Type类型 -->
<xs:complexType name="restrict_book_Type">
<xs:complexContent>
<!-- 通过限制book_Type类型派生新类型 -->
<xs:restriction base="book_Type">
<xs:sequence>
<!-- 为name元素的类型增加进一步约束 -->
<xs:element name="name">
<xs:simpleType>
<xs:restriction base="xs:token">
<xs:maxLength value="20"/>
<xs:minLength value="4"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<!-- 不再定义price元素,即可认为删除了该元素 -->
</xs:sequence>
<!-- 为publish-date属性的类型增加进一步约束 -->
<xs:attribute name="publish-date">
<xs:simpleType>
<xs:restriction base="xs:date">
<xs:maxExclusive value="2009-05-12"/>
<xs:minExclusive value="2007-05-12"/>
</xs:restriction>
</xs:simpleType>
</xs:attribute>
<!-- 删除isbn属性 -->
<xs:attribute name="isbn" use="prohibited"/>
</xs:restriction>
</xs:complexContent>
</xs:complexType>
<xs:element name="book" type="restrict_book_Type"/>
</xs:schema>
扩展混合内容类型
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified" attributeFormDefault="unqualified">
<!-- 定义一个book_Type类型,该类型下包含2个互斥子元素 -->
<xs:complexType name="book_Type" mixed="true">
<!-- 使用choice定义2个子元素 -->
<xs:choice>
<xs:element name="name" type="xs:token"/>
<xs:element name="price" type="xs:decimal"/>
</xs:choice>
</xs:complexType>
<!-- 定义extend_book_Type类型,必须保留mixed="true" -->
<xs:complexType name="extend_book_Type" mixed="true">
<xs:complexContent>
<!-- 通过扩展book_Type类型派生新类型 -->
<xs:extension base="book_Type">
<xs:choice>
<!-- 新增定义2个子元素 -->
<xs:element name="type" type="xs:token"/>
<xs:element name="targetMarket" type="xs:token"/>
</xs:choice>
</xs:extension>
</xs:complexContent>
</xs:complexType>
<xs:element name="book" type="extend_book_Type"/>
</xs:schema>
xml学习总结(三)的更多相关文章
- Android Animation学习(三) ApiDemos解析:XML动画文件的使用
Android Animation学习(三) ApiDemos解析:XML动画文件的使用 可以用XML文件来定义Animation. 文件必须有一个唯一的根节点: <set>, <o ...
- Java第三阶段学习(十、XML学习)
一.XML学习 1.模拟Servlet执行 在学习完前端及java与数据库后,将进行WEB编程阶段的学习.在WEB编程中,可以通过浏览器访问WEB服务器上的数据.这时WEB服务器就相当于另一台计算机. ...
- 从零开始学习jQuery (三) 管理jQuery包装集
本系列文章导航 从零开始学习jQuery (三) 管理jQuery包装集 一.摘要 在使用jQuery选择器获取到jQuery包装集后, 我们需要对其进行操作. 本章首先讲解如何动态的创建元素, 接着 ...
- XML 学习介绍 收藏
XML学习总结(一)——XML介绍 一.XML概念 Extensible Markup Language,翻译过来为可扩展标记语言.Xml技术是w3c组织发布的,目前推荐遵循的是W3C组织于2000发 ...
- XML学习笔记
XML学习笔记 第一部分:XML简介 我们经常可以听到XML.HTML.XHTML这些语言,后两者比较清楚,一直不是很明白XML是什么,这里做一个总结. XML(eXtensible Markup L ...
- JavaWeb学习总结(三)——Tomcat服务器学习和使用(二) 包含https 非对称秘钥 NB
JavaWeb学习总结(三)--Tomcat服务器学习和使用(二) 一.打包JavaWeb应用 在Java中,使用"jar"命令来对将JavaWeb应用打包成一个War包,jar命 ...
- MyEclipse Spring 学习总结三 SpringMVC
MyEclipse Spring 学习总结三 SpringMVC 一.SpringMVC原理 1.Springmvc 框架介绍 1)Spring 框架停工了构建Web应用程序的全功能MVC模块.Spr ...
- Quartz定时任务学习(二)web应用/Quartz定时任务学习(三)属性文件和jar
web中使用Quartz 1.首先在web.xml文件中加入 如下内容(根据自己情况设定) 在web.xml中添加QuartzInitializerServlet,Quartz为能够在web应用中使用 ...
- MyBatis学习系列三——结合Spring
目录 MyBatis学习系列一之环境搭建 MyBatis学习系列二——增删改查 MyBatis学习系列三——结合Spring MyBatis在项目中应用一般都要结合Spring,这一章主要把MyBat ...
随机推荐
- mysql颠覆实战笔记(八)--mysql的自定义异常处理怎么破
这一节课,沈老师带我们了解事务的异常 什么是异常? 我们先插入一组数据: ,10.5); 这个是正常的.但是我们把插入的user_money的值故意弄错:如下 ,‘abc’); 那么我们会得到一个ER ...
- SQL把做个字段组合成一个字符串
- Java中windows路径转换成linux路径等工具类
项目中发现别人写好的操作系统相关的工具类: 我总结的类似相关博客:http://www.cnblogs.com/DreamDrive/p/4289860.html import java.net.In ...
- Angular 2.0 从0到1 (七)
第一节:Angular 2.0 从0到1 (一)第二节:Angular 2.0 从0到1 (二)第三节:Angular 2.0 从0到1 (三)第四节:Angular 2.0 从0到1 (四)第五节: ...
- .net 创建属于自己的log类
实习到现在已经接近三个月了,由于是校企联合培养计划,所以没有工资,所幸公司对于我们这些实习生并没有什么要求,刚开始我还觉得要做点什么才能学得快,可是到了后来,发现公司安排给我们的任务并不紧要,也不算太 ...
- js如何判断一个数组中是否有重复的值
引自:http://bbs.tianya.cn/post-414-38497-1.shtml 方法一: var ary = new Array("111","22&quo ...
- sql查询统计,根据新闻类别ID统计,没有数据显示0
有两张表,新闻信息表MessageInfo和新闻类别表MessageType.表结构如下: 然后需要实现下面这种查询结果: 这个是我面试时遇到的,上面的新闻类型是乱写的.当时没有做出来,然后回来又研究 ...
- 给 Android 初学者的 Gradle 知识普及
给 Android 初学者的 Gradle 知识普及:http://gold.xitu.io/entry/5778f8bd165abd0054b443b0/promote?utm_source=bai ...
- Session id实现通过Cookie来传输方法及代码参考
1. Web中的Session指的就是用户在浏览某个网站时,从进入网站到浏览器关闭所经过的这段时间,也就是用户浏览这个网站所花费的时间.因此从上述的定义中我们可以看到,Session实际上是一个特定的 ...
- PHP学习笔记 - 进阶篇(6)
PHP学习笔记- 进阶篇(6) 会话控制(session与cookie) 当前的Cookie为: cookie简介 Cookie是存储在客户端浏览器中的数据,我们通过Cookie来跟踪与存储用户数据. ...