复杂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. Windows下用Eclipse搭建C/C++开发环境

    本文假定你已经熟悉Java,Eclipse的安装,并能顺利启动和运行Eclipse.此外因为各软件版本在不断更新,有些地方可能不准确,以最新的.原文资料为准. 距上一次写和调C++程序,已经5.6年了 ...

  2. GLOG使用注意事项

    FLAGS_stderrthreshold     输出到stderr的门限,默认为2(ERROR),默认,ERORR以下的信息不打印到终端 FLAGS_alsologtostderr 当这个全局变量 ...

  3. 小白日记7:kali渗透测试之主动信息收集-发现(一)--二层发现:arping/shell脚本,Netdiscover,scapy

    主动信息收集 被动信息收集可能不准确,可以用主动信息收集验证   特点:直接与目标系统交互通信,无法避免留下访问痕迹 解决方法:1.使用受控的第三方电脑进行探测,使用代理 (做好被封杀的准备)   2 ...

  4. isa-swizzling 是什么鬼?

    刚看到这个名字估计很多人有点熟悉,Method Swizzling对不对,不熟悉也没关系,去看看之前的一篇文章黑魔法之Method Swizzling吧.不过也可以根据名称猜测出来所谓的isa-swi ...

  5. df 和 du 命令详解

    df命令详细用法 a:显示全部的档案系统和各分割区的磁盘使用情形 i:显示i -nodes的使用量 k:大小用k来表示 (默认值) t:显示某一个档案系统的所有分割区磁盘使用量 x:显示不是某一个档案 ...

  6. CSS skills: 5) jquery hover(over,out)

    $(":div[name=div_edit]").each(function() { $(this).hover(function() { $(this).find("& ...

  7. Struts2的零配置和rest插件

    1. 零配置使用struts2-convention-plugin-2.3.16.jar,rest使用struts2-rest-plugin-2.3.16.jar 1.1 Struts2的conven ...

  8. plsql设置窗口默认格式

    一:plsql设置窗口默认格式 窗口视图设置完毕后,选择“窗口”菜单——点击“保存”版面. 等到下次重启后,就会呈现保存的版面. OK,设置完毕!

  9. 关于JDK中的集合总结(二)

    1.2版本的JDK才出现的java集合框架. 下面介绍说一下Vector的一些特点. import java.util.Enumeration; import java.util.Iterator; ...

  10. Nginx - Rewrite Module

    Initially, the purpose of this module (as the name suggests) is to perform URL rewriting. This mecha ...