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

    >> DTD, XML Schema(XMLS), RELAX NG
    [返回] 中文XML论坛 - 专业的XML技术讨论区XML.ORG.CN讨论区 - XML技术『 DTD/XML Schema 』 → 一个SCHEMA文件的两种写法! 查看新帖用户列表

      发表一个新主题  发表一个新投票  回复主题  (订阅本版) 您是本帖的第 6909 个阅读者浏览上一篇主题  刷新本主题   树形显示贴子 浏览下一篇主题
     * 贴子主题: 一个SCHEMA文件的两种写法! 举报  打印  推荐  IE收藏夹 
       本主题类别:     
     wedge 帅哥哟,离线,有人找我吗?
      
      
      等级:大一(猛啃高等数学)
      文章:35
      积分:153
      门派:XML.ORG.CN
      注册:2004/3/31

    姓名:(无权查看)
    城市:(无权查看)
    院校:(无权查看)
    给wedge发送一个短消息 把wedge加入好友 查看wedge的个人资料 搜索wedge在『 DTD/XML Schema 』的所有贴子 引用回复这个贴子 回复这个贴子 查看wedge的博客楼主
    发贴心情 一个SCHEMA文件的两种写法!


    book.xml
    **************************
    <?xml version="1.0" encoding="GB2312"?>
    <booklist xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xsi:nonamespaceschemalocation="book1.xsd">
      <book sales="N">
      <code>F8917</code>
      <title>ASP.net入门经典</title>
      <authorlist>
       <author>wedge</author>
      </authorlist>
      <price>590</price>
     </book>
     <book sales="N">
      <code>F8918</code>
      <title> 家常小菜</title>
      <authorlist>
       <author>wedge</author>
      </authorlist>
      <price>120</price>
     </book>
     </booklist>
    **************************************
    book1.xsd
    <?xml version="1.0" encoding="GB2312"?>
    <xs:element name="booklist">
      <xs:complexType>
       <xs:sequence>
        <xs:element name="book" type="booktype" maxOccurs="unbounded"/>
       </xs:sequence>
      </xs:complexType>
     </xs:element>
     <xs:complexType name="booktype">
      <xs:sequence>                                    
       <xs:element name="code" type="xs:string"/>
       <xs:element name="title" type="xs:string"/>
       <xs:element name="authorlist" type="authorlisttype"/>
       <xs:element name="price" type="price"/>
      </xs:sequence>
      <xs:attribute name="sales" use="required">
       <xs:simpleType>
        <xs:restriction base="xs:nmtoken">
         <xs:enumeration value="N"/>
         <xs:enumeration value="Y"/>
        </xs:restriction>   </xs:simpleType>
      </xs:attribute>
     </xs:complexType>
     <xs:complexType name="authorlisttype">
      <xs:sequence>
       <xs:element name="author" type="xs:string" fixed="wedge"/>
      </xs:sequence>
     </xs:complexType>
    </xs:schema>
    *************************************
    book2.xsd
    ************************
    <?xml version="1.0" encoding="GB2312"?>
    <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified">
     <xs:element name="booklist">
      <xs:complexType>
       <xs:sequence>
        <xs:element name="book" maxOccurs="unbounded">
                      <xs:complexType  >
        <xs:sequence>
            <xs:element name="code" type="xs:string"></xs:element>
    <xs:element name="title" type="xs:string"></xs:element>
    <xs:element name="authorlist">
    <xs:complexType >
    <xs:sequence>

    <xs:element name="author" type="xs:string"></xs:element>


    </xs:sequence>

    </xs:complexType>


    </xs:element>
    <xs:element name="price" type="xs:string"></xs:element>

        
        </xs:sequence>
          <xs:attribute name="sales" use="required">
       <xs:simpleType>
        <xs:restriction base="xs:nmtoken">
         <xs:enumeration value="N"/>
         <xs:enumeration value="Y"/>
        </xs:restriction>
       </xs:simpleType>
      </xs:attribute>
        </xs:complexType>
                  </xs:element>
       </xs:sequence>
      </xs:complexType>
     </xs:element>
    </xs:schema>
    主要是用了complextype实现的,偶认为book2.xsd的可读性没有book1.xsd的可读性好,book1.xsd是先定义好所需的结构类型,再在孙元素中引用。book2.xsd是直接用complextype定义子元素的。希望对大家有帮助!


       收藏   分享  
    顶(0)
      




    点击查看用户来源及管理<br>发贴IP:*.*.*.* 2004/4/21 20:41:00
     
     wedge 帅哥哟,离线,有人找我吗?
      
      
      等级:大一(猛啃高等数学)
      文章:35
      积分:153
      门派:XML.ORG.CN
      注册:2004/3/31

    姓名:(无权查看)
    城市:(无权查看)
    院校:(无权查看)
    给wedge发送一个短消息 把wedge加入好友 查看wedge的个人资料 搜索wedge在『 DTD/XML Schema 』的所有贴子 引用回复这个贴子 回复这个贴子 查看wedge的博客2
    发贴心情 
    再加上一种方法,利用complextype的子元素group来做。先定义一个group组,在element中用ref引用。
    bookgroup.xsd
    *********************
    <?xml version="1.0" encoding="GB2312"?>
    <xs:schema
    xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified">
    <xs:group name="bookdata"><xs:sequence>
       <xs:element name="code" type="xs:string"/>
       <xs:element name="title" type="xs:string"/>
       <xs:element name="authorlist" type="authorlisttype"/>
       <xs:element name="price" type="xs:decimal"/>
      </xs:sequence>
      </xs:group> 
      
     <xs:element name="booklist">
      <xs:complexType>
       <xs:sequence>
        <xs:element name="book" type="booktype" maxOccurs="unbounded"/>
       </xs:sequence>
      </xs:complexType>
     </xs:element>

     <xs:complexType name="booktype">
      <xs:sequence>
      <xs:group ref="bookdata" minOccurs="1" maxOccurs="1">
    </xs:group>
      
      </xs:sequence>
      <xs:attribute name="sales" use="required">
       <xs:simpleType>
        <xs:restriction base="xs:nmtoken">
         <xs:enumeration value="N"/>
         <xs:enumeration value="Y"/>
        </xs:restriction>
       </xs:simpleType>
      </xs:attribute>
     </xs:complexType>
     <xs:complexType name="authorlisttype">
      <xs:sequence>
       <xs:element name="author" type="xs:string" fixed="wedge"/>
      </xs:sequence>
     </xs:complexType>
    </xs:schema>

    点击查看用户来源及管理<br>发贴IP:*.*.*.* 2004/4/22 19:08:00
     
     wedge 帅哥哟,离线,有人找我吗?
      
      
      等级:大一(猛啃高等数学)
      文章:35
      积分:153
      门派:XML.ORG.CN
      注册:2004/3/31

    姓名:(无权查看)
    城市:(无权查看)
    院校:(无权查看)
    给wedge发送一个短消息 把wedge加入好友 查看wedge的个人资料 搜索wedge在『 DTD/XML Schema 』的所有贴子 引用回复这个贴子 回复这个贴子 查看wedge的博客3
    发贴心情 
    还可以有一种写法,把元素改为属性,用attributegroup来做。不过,好象属性写法不利于其结构化。
    点击查看用户来源及管理<br>发贴IP:*.*.*.* 2004/4/22 19:10:00
     
     GoogleAdSense
      
      
      等级:大一新生
      文章:1
      积分:50
      门派:无门无派
      院校:未填写
      注册:2007-01-01
    给Google AdSense发送一个短消息 把Google AdSense加入好友 查看Google AdSense的个人资料 搜索Google AdSense在『 DTD/XML Schema 』的所有贴子 访问Google AdSense的主页 引用回复这个贴子 回复这个贴子 查看Google AdSense的博客广告
    2024/4/28 19:49:29

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

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