复杂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. Android基本控件之RadioGroup

    我们在手机上经常看到一堆选项,但是我们只能选择一个,那么在Android中,这个控件就叫做RadioButton,也就是单选按钮的意思,他们之所以能够达到只能选择一个的效果,是因为有一个RadioGr ...

  2. Asp.Net 之 通过调用 WScript.Shell 启动本地 exe 程序时产生“ automation服务器不能创建对象 ”的错误

    我们经常需要通过生成 ActiveXObject("WScript.Shell"); 来调用某一exe文件. 设置网页打印的页眉页脚为空: var HKEY_Root,HKEY_P ...

  3. SQL语言的四大分类

    以下是sql数据语言类型的关键词: 1.数据定义语言DDL create.drop.alter.truncate 2.数据查询语言DQL  select 3.数据操纵语言DML insert.dele ...

  4. VB.net 字符串 分割 及 重新倒序组装

    ''' <summary> ''' split with ">>>>" , and inverted order ''' </summar ...

  5. hdu1501 动态规划

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

  6. 转 oracle 11g 导出空表

    1.Oracle11g默认对空表不分配segment,故使用exp导出Oracle11g数据库时,空表不会导出. 2.设置deferred_segment_creation 参数为FALSE后,无论是 ...

  7. AngularJS学习手册

    看书和视频结合是学习的最高效方式,看了这本书之后对angularjs才算是有一定的理解了.这本书以搭建一个博客为线索讲解了angularjs的知识点和实际项目开发流程.非常适合初学者!下面是我的读书笔 ...

  8. Asp_CRUD

    Asp_增删改查.逻辑流程 启动服务器. 地址为127.0.0.1 端口为随机分配 2607 然后在浏览器中输入http://localhost:2670/CRUD_main.ashx 浏览器像服务器 ...

  9. MVC中使用AuthorizeAttribute注意事项

    代码调用顺序为:OnAuthorization-->AuthorizeCore-->HandleUnauthorizedRequest 如果AuthorizeCore返回false时,才会 ...

  10. 自定义ListView适配器

    继承BaseAdapter类 覆盖以下4个方法: @Override public int getCount() { return users.size(); } @Override public O ...