2011-05-28 65 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

相關問題