2011-05-28 66 views
1

我想用我的xml模式完成的任务是为每个questionPool提出唯一的问题 - 并非针对所有questionPools。在我的XML文件,我有这样的代码,注释说什么我想要做的:XML Schema如何使每个元素的子元素都是唯一的?

<questionPools> 
    <questionPool> 
     <question idref="question1"/> 
     <question idref="question2"/> 
    </questionPool> 
    <questionPool> 
     <question idref="question3"/> 
     <question idref="question1"/> <!-- Duplicate but not in question pool so allowed --> 
     <question idref="question3"/> <!-- Not allowed because duplicate in question pool --> 
    </questionPool> 
</questionPools> 

我都试过,但它会检查所有问题而不是具体的人到一个池:

<xsd:key name="keyQuestionPool"> 
    <xsd:selector xpath="questionPools/questionPool/question"/> 
    <xsd:field xpath="@idref"/> 
</xsd:key> 

回答

0

范围的关键是包含元素。将<xs:key>定义作为<xs:element name="questionPool">元素定义的子元素,并从选择器的XPath中删除第一步以匹配新的上下文。

+0

非常感谢! – nefarel 2011-05-28 14:21:29

相关问题