`
MauerSu
  • 浏览: 495910 次
  • 性别: Icon_minigender_1
  • 来自: 北京
文章分类
社区版块
存档分类
最新评论

XSD文件详解

    博客分类:
  • rpcf
 
阅读更多
源:http://www.cnblogs.com/chenqingwei/archive/2010/05/10/1731743.html
评:
具体可参考:

http://blog.csdn.net/evanerv0079/archive/2008/06/05/2515313.aspx




复制代码
复制代码
<?xml version="1.0" encoding="gb2312"?>
<studentlist>
  <student id="A101">
    <name>李华</name>
    <sex>男</sex>
    <birthday>1978.9.12</birthday>
    <score>92</score>
    <skill>Java</skill>
    <skill>Oracle</skill>
    <skill>C Sharp</skill>
    <skill>SQL Server</skill>
  </student>
<studentlist>
复制代码


<?xml version="1.0" encoding="utf-8" ?>
<xs:schema id="原子类型" targetNamespace="http://student.com" elementFormDefault="qualified"
    xmlns="http://student.com" xmlns:mstns="http://student.com" xmlns:xs="http://www.w3.org/2001/XMLSchema">
    <xs:element name="student">
      <xs:complexType>
        <xs:sequence>
          <xs:element name="name" type="nameType"/> 
          <xs:element ref="age"/>
          <xs:element ref="sex"/>
          <xs:element ref="phone"/>
        </xs:sequence>
      </xs:complexType>
    </xs:element>
   
    <xs:simpleType name="nameType">
      <xs:restriction base="xs:string">
        <xs:minLength value="4"/>
        <xs:maxLength value="8"/>
      </xs:restriction>
    </xs:simpleType>
   
    <xs:element name="age">
      <xs:simpleType>
        <xs:restriction base="xs:int">
          <xs:minInclusive value="1"/>
          <xs:maxInclusive value="100"/>
        </xs:restriction>
      </xs:simpleType>
    </xs:element>
   
      <xs:element name="sex">
      <xs:simpleType>
        <xs:restriction base="xs:string">
          <xs:enumeration value="男"/>
          <xs:enumeration value="女"/>
        </xs:restriction>
      </xs:simpleType>
    </xs:element>
   
    <xs:element name="phone">
      <xs:simpleType>
        <xs:restriction base="xs:string">
          <xs:pattern value="\d{3}-\d{8}"/>
        </xs:restriction>
      </xs:simpleType>
    </xs:element>
</xs:schema>
复制代码



MSDN上面一个例子:


复制代码
  <!-- booksSchema.xml  -->    
   
  <?xml   version='1.0'?>  
  <!--   This   file   represents   a   fragment   of   a   book   store   inventory   database   -->  
  <bookstore   xmlns   =   "schema.xsd">  
      <book   genre="autobiography"   publicationdate="1981"   ISBN="1-861003-11-0">  
          <title>The   Autobiography   of   Benjamin   Franklin</title>  
          <author>  
              <first-name>Benjamin</first-name>  
              <last-name>Franklin</last-name>  
          </author>  
          <price>8.99</price>  
      </book>  
      <book   genre="novel"   publicationdate="1967"   ISBN="0-201-63361-2">  
          <title>The   Confidence   Man</title>  
          <author>  
              <first-name>Herman</first-name>  
              <last-name>Melville</last-name>  
          </author>  
          <price>11.99</price>  
      </book>  
      <book   genre="philosophy"   publicationdate="1991"   ISBN="1-861001-57-6">  
          <title>The   Gorgias</title>  
          <author>  
              <first-name>Sidas</first-name>  
              <last-name>Plato</last-name>  
          </author>  
          <price>9.99</price>  
      </book>  
  </bookstore>  
复制代码
<!-- schema.xsd --> 
   
  <xsd:schema   xmlns:xsd="http://www.w3.org/2001/XMLSchema"  
          xmlns="schema.xsd"  
          elementFormDefault="qualified"  
          targetNamespace="schema.xsd">  
   
    <xsd:element   name="bookstore"   type="bookstoreType"/>  
   
    <xsd:complexType   name="bookstoreType">  
      <xsd:sequence   maxOccurs="unbounded">  
        <xsd:element   name="book"     type="bookType"/>  
      </xsd:sequence>  
    </xsd:complexType>  
   
    <xsd:complexType   name="bookType">  
      <xsd:sequence>  
        <xsd:element   name="title"   type="xsd:string"/>  
        <xsd:element   name="author"   type="authorName"/>  
        <xsd:element   name="price"     type="xsd:decimal"/>  
      </xsd:sequence>  
      <xsd:attribute   name="genre"   type="xsd:string"/>  
      <xsd:attribute   name="publicationdate"   type="xsd:string"/>  
      <xsd:attribute   name="ISBN"   type="xsd:string"/>  
    </xsd:complexType>  
   
    <xsd:complexType   name="authorName">  
      <xsd:sequence>  
        <xsd:element   name="first-name"     type="xsd:string"/>  
        <xsd:element   name="last-name"   type="xsd:string"/>  
      </xsd:sequence>  
    </xsd:complexType>  
   
  </xsd:schema>  
复制代码
<!-- bookSchemaFail.xml   -->
   
  <?xml   version='1.0'?>  
  <bookstore   xmlns="schema.xsd">  
      <book>  
          <author>  
              <first-name>Benjamin</first-name>  
              <last-name>Franklin</last-name>  
          </author>  
      </book>  
      <book   genre="novel">  
          <title>The   Confidence   Man</title>  
          <author>  
              <first-name>Herman</first-name>  
              <last-name>Melville</last-name>  
          </author>  
          <price>11.99</price>  
      </book>  
      <book   genre="philosophy">  
          <title>The   Gorgias</title>  
          <author>  
              <name>Plato</name>  
          </author>  
          <price>9.99</price>  
      </book>  
  </bookstore>
分享到:
评论

相关推荐

    Schema教材

    schema文件详解: XML Schema 简介 为什么要使用 XML Schema? 如何使用 XSD? XSD 简易元素 XSD 属性 XSD 限定 / Facets XSD 复合元素

    JAVA web.xml配置详解

    &lt;web-app xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd...version="2.4"&gt; 网站名称 网站描述 &lt;!-- icon元素包含small-icon和large-icon两个子元素.用来指定web站台中小图标和大图标的路径....--small-icon元素应指向web站台中某个小图标的路径,大小为16 X 16...

    详解Java解析XML的四种方法

    对于XML本身的语法知识与技术细节,需要阅读相关的技术文献,这里面包括的内容有DOM(Document Object Model),DTD(Document Type Definition),SAX(Simple API for XML),XSD(Xml Schema Definition),XSLT(Extensible ...

    详解在Python程序中解析并修改XML内容的方法

    在实际应用中,需要对xml配置文件进行实时修改, 1.增加、删除 某些节点 2.增加,删除,修改某个节点下的某些属性 3.增加,删除,修改某些节点的文本 使用xml文档 &lt;?xml version=1.0 encoding=UTF-8?&gt; ...

    详解.net core日记记录

    ASP.NET Core 有内置的log组件,遗憾的是看了微软官方文档,貌似无法直接将日志存于文件或数据库,只能由自己实现或引用第三方日志组件。 以下为Nlog和log4net的使用记录 Nlog使用 搜索添加Nuget包 Nlog Nlog.Web....

    asp.net知识库

    技术基础 New Folder 多样式星期名字转换 [Design, C#] .NET关于string转换的一个小Bug Regular Expressions 完整的在.net后台执行javascript脚本...Serialize Your Deck with Positron [XML Serialization, XSD, C#]...

Global site tag (gtag.js) - Google Analytics