问题描述
我无法定义论文和作者之间的关系.可以定义一个吗?
<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>
推荐答案
我假设你希望"论文"有一个"作者".我在我的模式中这样做的方式是有一个作者列表和一个论文列表.像这样的:
<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>
选项卡搞砸了,但在我的示例中,每篇论文/作者都必须引用作者列表/作者.我会使用与此类似的架构代码来达到预期的效果:
<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>
所以论文/论文列表/论文/作者必须对应于论文/作者列表/作者,否则验证将引发错误.祝你好运!
问题描述
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!