XML关系 [英] XML Relationship

查看:142
本文介绍了XML关系的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法定义纸张和作者之间的关系。可以定义一个吗?

I am unable to define a relationship between paper and author. Is it possible to define one?

<xsd:complextype name="Researcher'>
</xsd:complextype>
<xsd:complexType name = "Paper" >
      <xsd:extension base = " Researcher " >
      </xsd:extension>
  </xsd:complexType>
<xsd:complexType name = "Author">
      <xsd:extension base = " Researcher ">
      </xsd:extension>
</xsd:complexType>


推荐答案

我假设你想要一个'论文'有一个'作者',我在我的模式中这样做的方法是列出作者和文件列表,这样一来:

I assume you want a 'paper' to have an 'author'. The way I do this in my schemas is to have a list of authors and a list of papers. Something like this:

<papers>

<authorlist>
    <author>Bob Barr</author>
    <author>Ron Paul</author>
    <author>Ralph Nader</author>
</authorlist>

<paperlist>
    <paper>
       <title>How to Revert Your Economy to the Gold Standard</title>
       <author>Ron Paul</author>
    </paper>
    <paper>
        <title>Unsafe at any Speed</title>
        <author>Ralph Nader</author>
    </paper>
     <paper>
         <title>How to be a Viable 3rd Party Candidate</title>
         <author>Bob Barr</author>
     </paper>
 </paperlist>
 </papers>

该标签被搞砸了,但在我的例子中,每篇文章/作者必须参考作者列表/作者。我将使用类似于此的模式代码来实现所需的效果:

The tabbing is messed up, but in my example every paper/author has to refer to an authorlist/author. I would use schema code similar to this to achieve the desired effect:

<xsd:element name="paper" type="Papers_Type">
    <xsd:unique name="Author_Key">
        <xsd:selector xpath="authorlist/author">
        <xsd:field xpath="text()"/>
    </xsd:key>
    <xsd:keyref name="Paper_Author_AuthorRef" refer="AuthorKey">
         <xsd:selector xpath="paperlist/paper/author"/>
         <xsd:field xpath="text()"/>
    </xsd:keyref>
</xsd:element>

<xsd:complextype name="Papers_Type">
    <!--Enter element definitions to your liking here-->
</xsd:complextype>

所以论文/论文列表/论文/作者必须对应于论文/作者/作者,否则验证将会抛出一个错误。祝你好运!

So papers/paperlist/paper/author has to correspond to papers/authorlist/author otherwise validation will throw an error. Good luck!

这篇关于XML关系的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆