XML Schema how to make sub-elements unique for each element?
What i want to accomplish with my xml schema is to make questions unique per questionPool - not for all questionPoo开发者_如何学JAVAls. In my xml file i have this code, comments say what i want to do:
<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>
I have tried this but it checks all questions rather then ones specific to one pool:
<xsd:key name="keyQuestionPool">
<xsd:selector xpath="questionPools/questionPool/question"/>
<xsd:field xpath="@idref"/>
</xsd:key>
The scope of the key is the containing element. Put the <xs:key>
definition as the child of the <xs:element name="questionPool">
element definition and drop the first steps from the XPath of the selector to match the new context.
精彩评论