新书推介:《语义网技术体系》
作者:瞿裕忠,胡伟,程龚
   XML论坛     W3CHINA.ORG讨论区     计算机科学论坛     SOAChina论坛     Blog     开放翻译计划     新浪微博  
 
  • 首页
  • 登录
  • 注册
  • 软件下载
  • 资料下载
  • 核心成员
  • 帮助
  •   Add to Google

    >> DTD, XML Schema(XMLS), RELAX NG
    [返回] 中文XML论坛 - 专业的XML技术讨论区XML.ORG.CN讨论区 - XML技术『 DTD/XML Schema 』 → [分享]一个完整的Schema,包含名称空间的使用,对不知道如何写Schema的同学很有帮助 查看新帖用户列表

      发表一个新主题  发表一个新投票  回复主题  (订阅本版) 您是本帖的第 9543 个阅读者浏览上一篇主题  刷新本主题   树形显示贴子 浏览下一篇主题
     * 贴子主题: [分享]一个完整的Schema,包含名称空间的使用,对不知道如何写Schema的同学很有帮助 举报  打印  推荐  IE收藏夹 
       本主题类别:     
     a309303973 帅哥哟,离线,有人找我吗?
      
      
      等级:大一新生
      文章:5
      积分:87
      门派:XML.ORG.CN
      注册:2008/4/2

    姓名:(无权查看)
    城市:(无权查看)
    院校:(无权查看)
    给a309303973发送一个短消息 把a309303973加入好友 查看a309303973的个人资料 搜索a309303973在『 DTD/XML Schema 』的所有贴子 引用回复这个贴子 回复这个贴子 查看a309303973的博客楼主
    发贴心情 [分享]一个完整的Schema,包含名称空间的使用,对不知道如何写Schema的同学很有帮助

    resume.xml:
    <?xml version="1.0" encoding="UTF-8"?>
    <resume xmlns="we:love:xml:schemas:but:we:hate:namespaces" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                     xsi:schemaLocation="we:love:xml:schemas:but:we:hate:namespaces resume.xsd">
                     
       <PersonName>
          <Names><Title>严振华</Title></Names>
       </PersonName>
       <Address>
          <StreetAddress>厦门大学海韵校区一期</StreetAddress>
          <City>厦门</City>
          <StateOrProvince>福建</StateOrProvince>
          <PostalCode>363105</PostalCode>
          <Country>China</Country>
       </Address>
       <PhoneNumber>*********</PhoneNumber>
       <Email>yzhxiada123456@126.com</Email>
       <Degree>undergraduate</Degree>
       
    </resume>  
    resume.xsd:
    <?xml version="1.0" encoding="UTF-8"?>
    <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xf="we:love:xml:schemas:but:we:hate:namespaces" targetNamespace="we:love:xml:schemas:but:we:hate:namespaces" elementFormDefault="qualified" attributeFormDefault="unqualified">
    <xs:include schemaLocation="reusable.xsd"/>
     <xs:element name="resume">
      <xs:complexType>
       <xs:sequence>
        <xs:element ref="xf:PersonName"/>
        <xs:element ref="xf:Address"/>
        <xs:element name="PhoneNumber" type="xf:PhoneType"/>
        <xs:element name="Email" type="xf:EmailType"/>
        <xs:element name="Degree" type="xf:DegreeType"/>
       </xs:sequence>
      </xs:complexType>
     </xs:element>
     <xs:element name="Address">
      <xs:complexType>
       <xs:sequence>
        <xs:element name="StreetAddress" type="xs:string" maxOccurs="unbounded"/>
        <xs:element name="City" type="xs:string"/>
        <xs:element name="StateOrProvince" type="xs:string" minOccurs="0"/>
        <xs:element name="PostalCode" type="xs:string"/>
        <xs:element name="Country" type="xf:CountryType"/>
       </xs:sequence>
      </xs:complexType>
     </xs:element>
     <xs:element name="PersonName">
      <xs:complexType>
       <xs:sequence>
        <xs:choice>
         <xs:element name="FullName" type="xs:string"/>
         <xs:element ref="xf:Names"/>
        </xs:choice>
       </xs:sequence>
      </xs:complexType>
     </xs:element>
     <xs:element name="Names">
      <xs:complexType>
       <xs:annotation>
        <xs:documentation>All parts of the names types are optional, and there may be multiple
        middle names, so it has a wrapper element.</xs:documentation>
       </xs:annotation>
       <xs:sequence>
        <xs:element name="Title" type="xs:string" minOccurs="0"/>
        <xs:element name="GivenName" type="xs:string" minOccurs="0"/>
        <xs:element name="MidleName" type="xs:string" minOccurs="0"/>
        <xs:element name="FamilyName" type="xs:string" minOccurs="0"/>
        <xs:element name="Suffix" type="xs:string" minOccurs="0"/>
       </xs:sequence>
      </xs:complexType>
     </xs:element>
     <xs:simpleType name="DegreeType">
      <xs:restriction base="xs:string">
       <xs:enumeration value="undergraduate"/>
       <xs:enumeration value="pupil"/>
       <xs:enumeration value="senior"/>
       <xs:enumeration value="graduate student"/>
       <xs:enumeration value="doctor"/>
       <xs:enumeration value="postdoctor"/>
      </xs:restriction>
     </xs:simpleType>
     <xs:simpleType name="PhoneType">
      <xs:restriction base="xs:string">
       <xs:minLength value="7"/>
       <xs:maxLength value="12"/>
      </xs:restriction>
     </xs:simpleType>
     <xs:simpleType name="EmailType">
      <xs:restriction base="xs:string">
       <xs:pattern value="[_a-z0-9-]+(\.[a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*"/>
      </xs:restriction>
     </xs:simpleType>
     
    </xs:schema>
    注意改xsd引用了reusable.xsd里的CountryType类型,还有是正则表达式的使用,注意xf的使用,因为有xmlns:xf="we:love:xml:schemas:but:we:hate:namespaces" targetNamespace="we:love:xml:schemas:but:we:hate:namespaces" elementFormDefault="qualified" attributeFormDefault="unqualified">,所以所有的全局元素和类型都属于空间we:love:xml:schemas:but:we:hate:namespaces,还有xml中的开头要导入名称空间xf。
    reusable.xsd:
    <?xml version="1.0" encoding="UTF-8"?>
    <xs:schema targetNamespace="we:love:xml:schemas:but:we:hate:namespaces"
     xmlns:xs="http://www.w3.org/2001/XMLSchema"
     xmlns:xf="we:love:xml:schemas:but:we:hate:namespaces" elementFormDefault="qualified"
     attributeFormDefault="unqualified">
     <xs:element name="Address" type="xf:AddressType">
      <xs:annotation>
       <xs:documentation>This reusable Address element draws on the AddressType from UBL. This
        element should be reused in your resume schema.</xs:documentation>
      </xs:annotation>
     </xs:element>
     <xs:complexType name="AddressType">
      <xs:annotation>
       <xs:documentation>This is a type meant to represent a generic address. It consists of an
        unlimited number of street addresses, a city, state or province, a postal code, and
        country. It is suggested that if need be, on a transform use conditional processing
        based on the Country element to get country specific layouts of the
       addresses.</xs:documentation>
      </xs:annotation>
      <xs:sequence>
       <xs:element name="StreetAddress" maxOccurs="unbounded" minOccurs="1" type="xs:string"/>
       <xs:element name="City" maxOccurs="1" minOccurs="1"/>
       <xs:element name="StateOrProvince" type="xs:string" maxOccurs="1" minOccurs="0"/>
       <xs:element name="PostalCode" type="xs:string" maxOccurs="1"/>
       <xs:element name="Country" type="xf:CountryType"/>
      </xs:sequence>
     </xs:complexType>
     <xs:simpleType name="CountryType">
      <xs:annotation>
       <xs:documentation>This is a restriction of the simple type String, limiting selection to
        only those valuses that represent actual countries or defacto autonomous countries.
        This list was taken from http://projectvisa.com/fullcountrylist.asp, and may or may
        not be complete.</xs:documentation>
      </xs:annotation>
      <xs:restriction base="xs:string">
       <xs:enumeration value="Afghanistan"/>
       <xs:enumeration value="Albania"/>
       <xs:enumeration value="Algeria"/>
       <xs:enumeration value="American Samoa"/>
       <xs:enumeration value="Andorra"/>
       <xs:enumeration value="Angola"/>
       <xs:enumeration value="Anguilla"/>
       <xs:enumeration value="Antigua and Barbuda"/>
       <xs:enumeration value="Argentina"/>
       <xs:enumeration value="Armenia"/>
       <xs:enumeration value="Aruba"/>
       <xs:enumeration value="Australia"/>
       <xs:enumeration value="Austria"/>
       <xs:enumeration value="Azerbaijan"/>
       <xs:enumeration value="Bahamas"/>
       <xs:enumeration value="Bahrain"/>
       <xs:enumeration value="Bangladesh"/>
       <xs:enumeration value="Barbados"/>
       <xs:enumeration value="Belarus"/>
       <xs:enumeration value="Belgium"/>
       <xs:enumeration value="Belize"/>
       <xs:enumeration value="Benin"/>
       <xs:enumeration value="Bermuda"/>
       <xs:enumeration value="Bhutan"/>
       <xs:enumeration value="Bolivia"/>
       <xs:enumeration value="Bosnia-Herzegovina"/>
       <xs:enumeration value="Botswana"/>
       <xs:enumeration value="Bouvet Island"/>
       <xs:enumeration value="Brazil"/>
       <xs:enumeration value="Brunei"/>
       <xs:enumeration value="Bulgaria"/>
       <xs:enumeration value="Burkina Faso"/>
       <xs:enumeration value="Burundi"/>
       <xs:enumeration value="Cambodia"/>
       <xs:enumeration value="Cameroon"/>
       <xs:enumeration value="Canada"/>
       <xs:enumeration value="Cape Verde"/>
       <xs:enumeration value="Cayman Islands"/>
       <xs:enumeration value="Central African Republic"/>
       <xs:enumeration value="Chad"/>
       <xs:enumeration value="Chile"/>
       <xs:enumeration value="China"/>
       <xs:enumeration value="Christmas Island"/>
       <xs:enumeration value="Cocos Islands"/>
       <xs:enumeration value="Colombia"/>
       <xs:enumeration value="Comoros"/>
       <xs:enumeration value="Conch Republic"/>
       <xs:enumeration value="Congo, Democratic Republic of the"/>
       <xs:enumeration value="Congo, Republic of"/>
       <xs:enumeration value="Cook Islands"/>
       <xs:enumeration value="Costa Rica"/>
       <xs:enumeration value="Croatia"/>
       <xs:enumeration value="Cuba"/>
       <xs:enumeration value="Cyprus"/>
       <xs:enumeration value="Czech Republic"/>
       <xs:enumeration value="Denmark"/>
       <xs:enumeration value="Djibouti"/>
       <xs:enumeration value="Dominica"/>
       <xs:enumeration value="Dominican Republic"/>
       <xs:enumeration value="Ecuador"/>
       <xs:enumeration value="Egypt"/>
       <xs:enumeration value="El Salvador"/>
       <xs:enumeration value="Equatorial Guinea"/>
       <xs:enumeration value="Eritrea"/>
       <xs:enumeration value="Estonia"/>
       <xs:enumeration value="Ethiopia"/>
       <xs:enumeration value="Falkland Islands"/>
       <xs:enumeration value="Faroe Islands"/>
       <xs:enumeration value="Fiji"/>
       <xs:enumeration value="Finland"/>
       <xs:enumeration value="France"/>
       <xs:enumeration value="French Guiana"/>
       <xs:enumeration value="Gabon"/>
       <xs:enumeration value="Gambia"/>
       <xs:enumeration value="Georgia"/>
       <xs:enumeration value="Germany"/>
       <xs:enumeration value="Ghana"/>
       <xs:enumeration value="Gibraltar"/>
       <xs:enumeration value="Greece"/>
       <xs:enumeration value="Greenland"/>
       <xs:enumeration value="Grenada"/>
       <xs:enumeration value="Guadeloupe"/>
       <xs:enumeration value="Guam"/>
       <xs:enumeration value="Guatemala"/>
       <xs:enumeration value="Guinea"/>
       <xs:enumeration value="Guinea Bissau"/>
       <xs:enumeration value="Guyana"/>
       <xs:enumeration value="Haiti"/>
       <xs:enumeration value="Holy See"/>
       <xs:enumeration value="Honduras"/>
       <xs:enumeration value="Hong Kong"/>
       <xs:enumeration value="Hungary"/>
       <xs:enumeration value="Iceland"/>
       <xs:enumeration value="India"/>
       <xs:enumeration value="Indonesia"/>
       <xs:enumeration value="Iran"/>
       <xs:enumeration value="Iraq"/>
       <xs:enumeration value="Ireland"/>
       <xs:enumeration value="Israel"/>
       <xs:enumeration value="Italy"/>
       <xs:enumeration value="Ivory Coast"/>
       <xs:enumeration value="Jamaica"/>
       <xs:enumeration value="Japan"/>
       <xs:enumeration value="Jordan"/>
       <xs:enumeration value="Kazakhstan"/>
       <xs:enumeration value="Kenya"/>
       <xs:enumeration value="Kiribati"/>
       <xs:enumeration value="Kuwait"/>
       <xs:enumeration value="Kyrgyzstan"/>
       <xs:enumeration value="Laos"/>
       <xs:enumeration value="Latvia"/>
       <xs:enumeration value="Lebanon"/>
       <xs:enumeration value="Lesotho"/>
       <xs:enumeration value="Liberia"/>
       <xs:enumeration value="Libya"/>
       <xs:enumeration value="Liechtenstein"/>
       <xs:enumeration value="Lithuania"/>
       <xs:enumeration value="Luxembourg"/>
       <xs:enumeration value="Macau"/>
       <xs:enumeration value="Macedonia"/>
       <xs:enumeration value="Madagascar"/>
       <xs:enumeration value="Malawi"/>
       <xs:enumeration value="Malaysia"/>
       <xs:enumeration value="Maldives"/>
       <xs:enumeration value="Mali"/>
       <xs:enumeration value="Malta"/>
       <xs:enumeration value="Marshall Islands"/>
       <xs:enumeration value="Martinique"/>
       <xs:enumeration value="Mauritania"/>
       <xs:enumeration value="Mauritius"/>
       <xs:enumeration value="Mayotte"/>
       <xs:enumeration value="Mexico"/>
       <xs:enumeration value="Micronesia"/>
       <xs:enumeration value="Moldova"/>
       <xs:enumeration value="Monaco"/>
       <xs:enumeration value="Mongolia"/>
       <xs:enumeration value="Montserrat"/>
       <xs:enumeration value="Morocco"/>
       <xs:enumeration value="Mozambique"/>
       <xs:enumeration value="Myanmar"/>
       <xs:enumeration value="Namibia"/>
       <xs:enumeration value="Nauru"/>
       <xs:enumeration value="Nepal"/>
       <xs:enumeration value="Netherlands"/>
       <xs:enumeration value="Netherlands Antilles"/>
       <xs:enumeration value="New Caledonia"/>
       <xs:enumeration value="New Zealand"/>
       <xs:enumeration value="Nicaragua"/>
       <xs:enumeration value="Niger"/>
       <xs:enumeration value="Nigeria"/>
       <xs:enumeration value="Niue"/>
       <xs:enumeration value="Norfolk Island"/>
       <xs:enumeration value="North Korea"/>
       <xs:enumeration value="Northern Mariana Islands"/>
       <xs:enumeration value="Norway"/>
       <xs:enumeration value="Oman"/>
       <xs:enumeration value="Pakistan"/>
       <xs:enumeration value="Palau"/>
       <xs:enumeration value="Panama"/>
       <xs:enumeration value="Papua New Guinea"/>
       <xs:enumeration value="Paraguay"/>
       <xs:enumeration value="Peru"/>
       <xs:enumeration value="Philippines"/>
       <xs:enumeration value="Pitcairn Island"/>
       <xs:enumeration value="Poland"/>
       <xs:enumeration value="Polynesia"/>
       <xs:enumeration value="Portugal"/>
       <xs:enumeration value="Puerto Rico"/>
       <xs:enumeration value="Qatar"/>
       <xs:enumeration value="Reunion"/>
       <xs:enumeration value="Romania"/>
       <xs:enumeration value="Russia"/>
       <xs:enumeration value="Rwanda"/>
       <xs:enumeration value="S. Georgia and S. Sandwich Isls."/>
       <xs:enumeration value="Saint Kitts and Nevis"/>
       <xs:enumeration value="Saint Lucia"/>
       <xs:enumeration value="Saint Pierre and Miquelon"/>
       <xs:enumeration value="Saint Vincent and Grenadines"/>
       <xs:enumeration value="Samoa"/>
       <xs:enumeration value="San Marino"/>
       <xs:enumeration value="Sao Tome and Principe"/>
       <xs:enumeration value="Saudi Arabia"/>
       <xs:enumeration value="Schengen countries"/>
       <xs:enumeration value="Senegal"/>
       <xs:enumeration value="Serbia and Montenegro"/>
       <xs:enumeration value="Seychelles"/>
       <xs:enumeration value="Sierra Leone"/>
       <xs:enumeration value="Singapore"/>
       <xs:enumeration value="Slovakia"/>
       <xs:enumeration value="Slovenia"/>
       <xs:enumeration value="Solomon Islands"/>
       <xs:enumeration value="Somalia"/>
       <xs:enumeration value="South Africa"/>
       <xs:enumeration value="South Korea"/>
       <xs:enumeration value="Spain"/>
       <xs:enumeration value="Sri Lanka"/>
       <xs:enumeration value="Sudan"/>
       <xs:enumeration value="Suriname"/>
       <xs:enumeration value="Svalbard and Jan Mayen Islands"/>
       <xs:enumeration value="Swaziland"/>
       <xs:enumeration value="Sweden"/>
       <xs:enumeration value="Switzerland"/>
       <xs:enumeration value="Syria"/>
       <xs:enumeration value="Taiwan"/>
       <xs:enumeration value="Tajikistan"/>
       <xs:enumeration value="Tanzania"/>
       <xs:enumeration value="Thailand"/>
       <xs:enumeration value="Timor-Leste"/>
       <xs:enumeration value="Togo"/>
       <xs:enumeration value="Tokelau"/>
       <xs:enumeration value="Tonga"/>
       <xs:enumeration value="Trinidad and Tobago"/>
       <xs:enumeration value="Tunisia"/>
       <xs:enumeration value="Turkey"/>
       <xs:enumeration value="Turkmenistan"/>
       <xs:enumeration value="Turks and Caicos Islands"/>
       <xs:enumeration value="Tuvalu"/>
       <xs:enumeration value="Uganda"/>
       <xs:enumeration value="Ukraine"/>
       <xs:enumeration value="United Arab Emirates"/>
       <xs:enumeration value="United Kingdom"/>
       <xs:enumeration value="United States"/>
       <xs:enumeration value="Uruguay"/>
       <xs:enumeration value="Uzbekistan"/>
       <xs:enumeration value="Vanuatu"/>
       <xs:enumeration value="Venezuela"/>
       <xs:enumeration value="Vietnam"/>
       <xs:enumeration value="Virgin Islands"/>
       <xs:enumeration value="Wallis and Futuna Islands"/>
       <xs:enumeration value="Yemen"/>
       <xs:enumeration value="Zambia"/>
       <xs:enumeration value="Zimbabwe"/>
      </xs:restriction>
     </xs:simpleType>
     <xs:complexType name="PersonalNameType">
      <xs:annotation>
       <xs:documentation>And now we create a personal name type within this schema's namespace.
        The personal name element can either be one long string of the full name or a series
        of elements for each part of the name. This type should be reused in your resume
        schema.</xs:documentation>
      </xs:annotation>
      <xs:sequence>
       <xs:choice>
        <xs:element name="FullName" type="xs:string"/>
        <xs:element name="Names" type="xf:NamesType"/>
       </xs:choice>
      </xs:sequence>
     </xs:complexType>
     <xs:complexType name="NamesType">
      <xs:annotation>
       <xs:documentation>All parts of the names types are optional, and there may be multiple
        middle names, so it has a wrapper element.</xs:documentation>
      </xs:annotation>
      <xs:sequence>
       <xs:element name="Title" type="xs:string" minOccurs="0"/>
       <xs:element name="GivenName" type="xs:string" minOccurs="0"/>
       <xs:element name="MiddleNames" type="xf:MiddleNamesType" minOccurs="0"/>
       <xs:element name="FamilyName" type="xs:string" minOccurs="0"/>
       <xs:element name="Suffix" type="xs:string" minOccurs="0"/>
      </xs:sequence>
     </xs:complexType>
     <xs:complexType name="MiddleNamesType">
      <xs:annotation>
       <xs:documentation>And finally, the list of middle names.</xs:documentation>
      </xs:annotation>
      <xs:sequence>
       <xs:element name="MiddleName" type="xs:string" maxOccurs="unbounded"/>
      </xs:sequence>
     </xs:complexType>
    </xs:schema>

       收藏   分享  
    顶(0)
      




    点击查看用户来源及管理<br>发贴IP:*.*.*.* 2008/4/2 21:56:00
     
     GoogleAdSense
      
      
      等级:大一新生
      文章:1
      积分:50
      门派:无门无派
      院校:未填写
      注册:2007-01-01
    给Google AdSense发送一个短消息 把Google AdSense加入好友 查看Google AdSense的个人资料 搜索Google AdSense在『 DTD/XML Schema 』的所有贴子 访问Google AdSense的主页 引用回复这个贴子 回复这个贴子 查看Google AdSense的博客广告
    2024/12/22 1:25:14

    本主题贴数1,分页: [1]

    管理选项修改tag | 锁定 | 解锁 | 提升 | 删除 | 移动 | 固顶 | 总固顶 | 奖励 | 惩罚 | 发布公告
    W3C Contributing Supporter! W 3 C h i n a ( since 2003 ) 旗 下 站 点
    苏ICP备05006046号《全国人大常委会关于维护互联网安全的决定》《计算机信息网络国际联网安全保护管理办法》
    94.238ms