复杂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学习总结(三)的更多相关文章

  1. Android Animation学习(三) ApiDemos解析:XML动画文件的使用

    Android Animation学习(三) ApiDemos解析:XML动画文件的使用 可以用XML文件来定义Animation. 文件必须有一个唯一的根节点: <set>, <o ...

  2. Java第三阶段学习(十、XML学习)

    一.XML学习 1.模拟Servlet执行 在学习完前端及java与数据库后,将进行WEB编程阶段的学习.在WEB编程中,可以通过浏览器访问WEB服务器上的数据.这时WEB服务器就相当于另一台计算机. ...

  3. 从零开始学习jQuery (三) 管理jQuery包装集

    本系列文章导航 从零开始学习jQuery (三) 管理jQuery包装集 一.摘要 在使用jQuery选择器获取到jQuery包装集后, 我们需要对其进行操作. 本章首先讲解如何动态的创建元素, 接着 ...

  4. XML 学习介绍 收藏

    XML学习总结(一)——XML介绍 一.XML概念 Extensible Markup Language,翻译过来为可扩展标记语言.Xml技术是w3c组织发布的,目前推荐遵循的是W3C组织于2000发 ...

  5. XML学习笔记

    XML学习笔记 第一部分:XML简介 我们经常可以听到XML.HTML.XHTML这些语言,后两者比较清楚,一直不是很明白XML是什么,这里做一个总结. XML(eXtensible Markup L ...

  6. JavaWeb学习总结(三)——Tomcat服务器学习和使用(二) 包含https 非对称秘钥 NB

    JavaWeb学习总结(三)--Tomcat服务器学习和使用(二) 一.打包JavaWeb应用 在Java中,使用"jar"命令来对将JavaWeb应用打包成一个War包,jar命 ...

  7. MyEclipse Spring 学习总结三 SpringMVC

    MyEclipse Spring 学习总结三 SpringMVC 一.SpringMVC原理 1.Springmvc 框架介绍 1)Spring 框架停工了构建Web应用程序的全功能MVC模块.Spr ...

  8. Quartz定时任务学习(二)web应用/Quartz定时任务学习(三)属性文件和jar

    web中使用Quartz 1.首先在web.xml文件中加入 如下内容(根据自己情况设定) 在web.xml中添加QuartzInitializerServlet,Quartz为能够在web应用中使用 ...

  9. MyBatis学习系列三——结合Spring

    目录 MyBatis学习系列一之环境搭建 MyBatis学习系列二——增删改查 MyBatis学习系列三——结合Spring MyBatis在项目中应用一般都要结合Spring,这一章主要把MyBat ...

随机推荐

  1. 产品设计原则之移动APP【转】

    随着移动互联网的发展,越来越多的Web产品开始布局移动端,因此最近经常碰到PM们在交流讨论移动APP产品的设计.我从事移动互联网已经有一年多了,通过不断的学习和实践也积累了一些心得,今天整理并分享一下 ...

  2. 管理Activity

     开源中国摘取的代码,这个可以管理activity 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 ...

  3. git 在windows上 生成ssh公钥

    今天上传代码到服务器时,报如下错误:   上网搜了一下,应该是ssh过期了.我们就来生成新的ssh公钥吧.   1. 打开git bash   2. 输入命令:  ssh-keygen -t rsa ...

  4. u-boot移植为tiny6410步骤

    1. 修改顶层Makefile文件 2. 修改arch/arm/cpu/arm1176/s3c64xx/cpu_init.S 3. 修改arch/arm/cpu/arm1176/s3c64xx/Mak ...

  5. webservice简单总结

    一:webservice定义 webservice是一种基于xml,xsd封装格式,通过http协议通信的一种服务,支持跨平台.跨语言的 远程调用. 二:webservice优点 1:跨平台,无论是w ...

  6. 【贪心+一点小思路】Zoj - 3829 Known Notation

    借用别人一句话,还以为是个高贵的dp... ... 一打眼一看是波兰式的题,有点懵还以为要用后缀表达式或者dp以下什么什么的,比赛后半阶段才开始仔细研究这题发现贪心就能搞,奈何读错题了!!交换的时候可 ...

  7. hdu1501 动态规划

    这题有两种解题思路,一个是记忆化搜索,一个是dp. 分别贴代码: 记忆化搜索: #include<iostream> #include<cstdio> #include< ...

  8. (转载)运行主机管理在openvswitch之上

    在这篇文章里介绍了如果运行主机管理在openvswitch之上,而不是单独配置一个物理网卡用于主机管理,并且所有的vm的流量还是通过openvswitch走的. Running Host Manage ...

  9. this指针在不同情况下的指代

     说不同情况了吧,首先要分有几种情况使用this,然后再说分别指代什么 1)如果是一般标签下函数调用,this指代全局对象,也就是window对象或者document对象 2)如果在嵌套函数中被嵌套的 ...

  10. Jersey(1.19.1) - Security

    Security information is available by obtaining the SecurityContext using @Context, which is essentia ...