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 ...
随机推荐
- javascript 十六进制与RGB颜色值的相互转换
http://www.zhangxinxu.com/wordpress/?p=646 http://www.zhangxinxu.com/wordpress/?p=646 -------------- ...
- jar包冲突解决方法
import java.io.File;import java.io.IOException;import java.util.ArrayList;import java.util.Enumerati ...
- 移动互联网(APP)产品设计的经验分享【转】
随着移动互联网的发展,越来越多的Web产品开始布局移动端,因此最近经常碰到PM们在交流讨论移动APP产品的设计.我从事移动互联网已经有一年多了,通过不断的学习和实践也积累了一些心得,今天整理并分享一下 ...
- South——谁说Django不能migrate!
零.前言 最近改一个项目,需要对已有的model进行更改.大家都知道Django自带的syncdb只能创建数据库,但是无法将已经改变的model应用的数据库中. 大概两年前遇到这个问题的时候,网上的答 ...
- jquery 页面跳转 表单提交
$("#button").click(function () { $("#form").first().attr("action ...
- LeetCode 278
First Bad Version You are a product manager and currently leading a team to develop a new product. U ...
- 神奇的CSS3选择器
话说园子里也混迹多年了,但是基本没写过blog,写点基础的,那就从css3选择器开始吧. Css3选择器 先说下,为什么提倡使用选择器. 使用选择器可以将样式与元素直接绑定起来,在样式表中什么样式与什 ...
- MySql索引的优缺点
优点 有了索引.对于记录数量很多的表,可以提高查询速度. 缺点 索引是占用空间的. 索引会影响update insert delete速度 ALERT!!! 1.索引要创建在where和join用到的 ...
- response小结(五)—通过response实现请求重定向
请求重定向指的是一个web资源收到客户端请求后,通知客户端去访问另外一个web资源,这称之为请求重定向.302状态码和location头即可实现重定向. 请求重定向最常见的应用场景就是用户登录. 下面 ...
- CSS 文字溢出时的自动隐藏
http://www.111cn.net/cssdiv/css/34050.htm 语法:overflow : visible | auto | hidden | scroll visible::不剪 ...