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

    >> DTD, XML Schema(XMLS), RELAX NG
    [返回] 中文XML论坛 - 专业的XML技术讨论区XML.ORG.CN讨论区 - XML技术『 DTD/XML Schema 』 → 同样的元素名称,属性值不同,怎么写schema呢?谢谢 查看新帖用户列表

      发表一个新主题  发表一个新投票  回复主题  (订阅本版) 您是本帖的第 5858 个阅读者浏览上一篇主题  刷新本主题   树形显示贴子 浏览下一篇主题
     * 贴子主题: 同样的元素名称,属性值不同,怎么写schema呢?谢谢 举报  打印  推荐  IE收藏夹 
       本主题类别:     
     wise 帅哥哟,离线,有人找我吗?
      
      
      等级:大一(猛啃高等数学)
      文章:25
      积分:163
      门派:XML.ORG.CN
      注册:2005/3/15

    姓名:(无权查看)
    城市:(无权查看)
    院校:(无权查看)
    给wise发送一个短消息 把wise加入好友 查看wise的个人资料 搜索wise在『 DTD/XML Schema 』的所有贴子 引用回复这个贴子 回复这个贴子 查看wise的博客楼主
    发贴心情 同样的元素名称,属性值不同,怎么写schema呢?谢谢

    比如要写这样一个例子:
    有三种Node元素,有一个type属性,可以为a或b或c,现在要求3种里面随意出现一个
    我如下写,好像不行,不知道为什么
    <xsd:choice>
      <xsd:element name="Node" Type="AType">
        <xsd:complexType>
          <xsd:attribute name="type" Type="xsd:string" fixed="a"/>
        </xsd:complexType>
      </xsd:element>
      <xsd:element name="Node" Type="BType">
        <xsd:complexType>
          <xsd:attribute name="type" Type="xsd:string" fixed="b"/>
        </xsd:complexType>
      </xsd:element>
      <xsd:element name="Node" Type="CType">
        <xsd:complexType>
          <xsd:attribute name="type" Type="xsd:string" fixed="c"/>
        </xsd:complexType>
      </xsd:element>
    </xsd:choice>

    这样写好像不行,可能原因是我用了同样的Name,都是Node,但是我就是要同样的Name阿,我不知道怎么写了:(
    大虾帮帮忙吧


       收藏   分享  
    顶(0)
      




    ----------------------------------------------
    XML什么都不做

    点击查看用户来源及管理<br>发贴IP:*.*.*.* 2007/2/12 1:41:00
     
     upzone 帅哥哟,离线,有人找我吗?
      
      等级:大一(高数修炼中)
      文章:4
      积分:122
      门派:XML.ORG.CN
      注册:2004/11/17

    姓名:(无权查看)
    城市:(无权查看)
    院校:(无权查看)
    给upzone发送一个短消息 把upzone加入好友 查看upzone的个人资料 搜索upzone在『 DTD/XML Schema 』的所有贴子 引用回复这个贴子 回复这个贴子 查看upzone的博客2
    发贴心情 
    Attribute没有 choice的属性,Attribute必须要依赖于Element存在,我换了一种方法变通实现.
    1.Schema
    <?xml version="1.0" encoding="UTF-8"?>
    <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="unqualified">
     <xs:element name="ChoiceAttribute">
      <xs:annotation>
       <xs:documentation>Att</xs:documentation>
      </xs:annotation>
      <xs:complexType>
       <xs:sequence maxOccurs="unbounded">
        <xs:element name="Nodes" type="NodeType"/>
       </xs:sequence>
      </xs:complexType>
     </xs:element>
     <xs:complexType name="NodeType" abstract="true">
      <xs:sequence>
       <xs:element name="Node" type="xs:string"/>
      </xs:sequence>
      <xs:attributeGroup ref="ABCGroup"/>
      <xs:attribute name="C"/>
     </xs:complexType>
     <xs:attributeGroup name="ABCGroup">
      <xs:attribute name="A" type="xs:string" use="optional"/>
      <xs:attribute name="B" type="xs:string" use="optional"/>
     </xs:attributeGroup>
     <xs:complexType name="NodeTypeA">
      <xs:complexContent>
       <xs:restriction base="NodeType">
        <xs:sequence>
         <xs:element name="Node" type="xs:string"/>
        </xs:sequence>
        <xs:attribute name="A" type="xs:string" use="optional"/>
        <xs:attribute name="B" type="xs:string" use="prohibited"/>
        <xs:attribute name="C" use="prohibited"/>
       </xs:restriction>
      </xs:complexContent>
     </xs:complexType>
     <xs:complexType name="NodeTypeB">
      <xs:complexContent>
       <xs:restriction base="NodeType">
        <xs:sequence>
         <xs:element name="Node" type="xs:string"/>
        </xs:sequence>
        <xs:attribute name="B" type="xs:string" use="optional"/>
        <xs:attribute name="A" type="xs:string" use="prohibited"/>
        <xs:attribute name="C" use="prohibited"/>
       </xs:restriction>
      </xs:complexContent>
     </xs:complexType>
     <xs:complexType name="NodeTypeC">
      <xs:complexContent>
       <xs:restriction base="NodeType">
        <xs:sequence>
         <xs:element name="Node" type="xs:string"/>
        </xs:sequence>
        <xs:attribute name="A" type="xs:string" use="prohibited"/>
        <xs:attribute name="B" type="xs:string" use="prohibited"/>
        <xs:attribute name="C" type="xs:string" use="required"/>
       </xs:restriction>
      </xs:complexContent>
     </xs:complexType>
    </xs:schema>

    2.Sample XML

    <?xml version="1.0" encoding="UTF-8"?>
    <!--Sample XML file generated by XMLSpy v2007 sp1 (http://www.altova.com)-->
    <ChoiceAttribute xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="ChoiceAttribute.xsd">
     <Nodes xsi:type="NodeTypeA" A="String">
      <Node>String</Node>
     </Nodes>
     <Nodes xsi:type="NodeTypeB" B="String">
      <Node>String</Node>
     </Nodes>
     <Nodes xsi:type="NodeTypeC" C="String">
      <Node>String</Node>
     </Nodes>
    </ChoiceAttribute>


    通过继承方式来实现,不过需要在xml instance里添加属性xsi:type 来标记具体的类型
    只是一种实现方式,比较麻烦。不对之处,请指教。

    点击查看用户来源及管理<br>发贴IP:*.*.*.* 2007/2/12 17:08:00
     
     wise 帅哥哟,离线,有人找我吗?
      
      
      等级:大一(猛啃高等数学)
      文章:25
      积分:163
      门派:XML.ORG.CN
      注册:2005/3/15

    姓名:(无权查看)
    城市:(无权查看)
    院校:(无权查看)
    给wise发送一个短消息 把wise加入好友 查看wise的个人资料 搜索wise在『 DTD/XML Schema 』的所有贴子 引用回复这个贴子 回复这个贴子 查看wise的博客3
    发贴心情 
    可能是我表达不清楚……我希望的xml文件是这样的
    <Nodes>
      <Node type="a">我是A点</Node>
      <Node type="c">我是C点</Node>
      <Node type="b">我是B点</Node>
      <Node type="c">我又是C点</Node>
      <Node type="a">我们出现没什么规律</Node>
      <Node type="c">我是C点,想出现几遍就出现几遍</Node>
      <Node type="b">我是B点,其实我不出现也无所谓</Node>
    </Nodes>

    ----------------------------------------------
    XML什么都不做

    点击查看用户来源及管理<br>发贴IP:*.*.*.* 2007/2/13 0:07:00
     
     upzone 帅哥哟,离线,有人找我吗?
      
      等级:大一(高数修炼中)
      文章:4
      积分:122
      门派:XML.ORG.CN
      注册:2004/11/17

    姓名:(无权查看)
    城市:(无权查看)
    院校:(无权查看)
    给upzone发送一个短消息 把upzone加入好友 查看upzone的个人资料 搜索upzone在『 DTD/XML Schema 』的所有贴子 引用回复这个贴子 回复这个贴子 查看upzone的博客4
    发贴心情 
    Sorry,看错了,不过你这样还不如直接Node 节点循环,而Node的type attribute设定enumeration a,b,c

    <?xml version="1.0" encoding="UTF-8"?>
    <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="unqualified">
     <xs:element name="Nodes">
      <xs:complexType>
       <xs:sequence maxOccurs="unbounded">
        <xs:element name="Node">
         <xs:complexType>
          <xs:attribute name="type">
           <xs:simpleType>
            <xs:restriction base="xs:string">
             <xs:enumeration value="a"/>
             <xs:enumeration value="b"/>
             <xs:enumeration value="c"/>
            </xs:restriction>
           </xs:simpleType>
          </xs:attribute>
         </xs:complexType>
        </xs:element>
       </xs:sequence>
      </xs:complexType>
     </xs:element>

    点击查看用户来源及管理<br>发贴IP:*.*.*.* 2007/2/13 0:58:00
     
     wise 帅哥哟,离线,有人找我吗?
      
      
      等级:大一(猛啃高等数学)
      文章:25
      积分:163
      门派:XML.ORG.CN
      注册:2005/3/15

    姓名:(无权查看)
    城市:(无权查看)
    院校:(无权查看)
    给wise发送一个短消息 把wise加入好友 查看wise的个人资料 搜索wise在『 DTD/XML Schema 』的所有贴子 引用回复这个贴子 回复这个贴子 查看wise的博客5
    发贴心情 
    这个办法我想过,但是有个问题
    我需要当type=a的时候内容形式和b还有c都不一样
    比如a节点是string
    b是int
    c是嵌套其他元素
    我不知道怎么区分开这些node,并且与自身的type属性绑定

    ----------------------------------------------
    XML什么都不做

    点击查看用户来源及管理<br>发贴IP:*.*.*.* 2007/2/13 16:00:00
     
     wise 帅哥哟,离线,有人找我吗?
      
      
      等级:大一(猛啃高等数学)
      文章:25
      积分:163
      门派:XML.ORG.CN
      注册:2005/3/15

    姓名:(无权查看)
    城市:(无权查看)
    院校:(无权查看)
    给wise发送一个短消息 把wise加入好友 查看wise的个人资料 搜索wise在『 DTD/XML Schema 』的所有贴子 引用回复这个贴子 回复这个贴子 查看wise的博客6
    发贴心情 
    大大快显身阿,天天在线等呢,谢谢!

    ----------------------------------------------
    XML什么都不做

    点击查看用户来源及管理<br>发贴IP:*.*.*.* 2007/2/14 13:50:00
     
     gemingke 帅哥哟,离线,有人找我吗?
      
      
      威望:2
      等级:计算机学士学位
      文章:321
      积分:2078
      门派:XML.ORG.CN
      注册:2005/9/21

    姓名:(无权查看)
    城市:(无权查看)
    院校:(无权查看)
    给gemingke发送一个短消息 把gemingke加入好友 查看gemingke的个人资料 搜索gemingke在『 DTD/XML Schema 』的所有贴子 点击这里发送电邮给gemingke 引用回复这个贴子 回复这个贴子 查看gemingke的博客7
    发贴心情 
    xml里面,同名元素不能使用不同的数据类型,除非你使用namespce,但那样会使问题更加复杂

    ----------------------------------------------
    天下英雄谁敌手?曹刘,生子当如孙仲谋!

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

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

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