相关疑难解决方法(0)

具有多个字段的XML Schema Key

我有一个包含问题结构的XML文件格式:

<question id="q101">
  <text>Do you like the color red?</text>
  <answer>yes</answer>
  <answer>no</answer>
</question>
<question id="q102">
  <text>What is your favorite color?</text>
  <answer>red</answer>
  <answer>blue</answer>
  <answer>white</answer>
  <answer>yellow</answer>
</question>
Run Code Online (Sandbox Code Playgroud)

我也有来自多个用户的相同文件响应.

<user id="bob">
  <response questionIdRef="q101">yes</response>
  <response questionIdRef="q102">white</response>
</user>
<user id="jane">
  <response questionIdRef="q101">no</response>
  <response questionIdRef="q102">blue</response>
</user>
Run Code Online (Sandbox Code Playgroud)

我已经在xml中为questionId定义了一个键和一个keyref元素:

<xsd:key name="questionId">
  <xsd:selector xpath=".//question" />
  <xsd:field xpath="@id" />
</xsd:key>
<xsd:keyref name="responseQuestionIdKeyRef" refer="questionId">
  <xsd:selector xpath=".//response" />
  <xsd:field xpath="@questionIdRef" />
</xsd:keyref>
Run Code Online (Sandbox Code Playgroud)

我现在想要做的是现在让模式验证用户对某个问题的响应的值实际上是引用问题中提供的答案.我尝试使用以下密钥和keyref执行此操作,但它只能识别第一个答案,所有其他答案都未被识别为有效:

<xsd:key name="answerValue">
  <xsd:selector xpath=".//question" />
  <xsd:field xpath="@id" />
  <xsd:field xpath=".//answer/value" />
</xsd:key>
<xsd:keyref name="validAnswer" refer="answerValue">
  <xsd:selector xpath=".//response" />
  <xsd:field xpath="@questionIdRef" …
Run Code Online (Sandbox Code Playgroud)

xml schema xsd

2
推荐指数
1
解决办法
1万
查看次数

标签 统计

schema ×1

xml ×1

xsd ×1