【发布时间】:2021-10-14 01:32:43
【问题描述】:
现在我有一个允许用户创建多项选择题的系统。用户(理想情况下)会像这样使用它们:
<MultipleChoice>
<Choices>
<Choice>a) apple</Choice>
<Choice>b) banana</Choice>
<Choice correct="true">c) grapes</Choice>
</Choices>
</MultipleChoice>
注意葡萄的正确属性。使用它是为了当我在 UI 中渲染它时,它旁边有一个绿色复选标记。但是,对于我当前的 xsd,我无法阻止用户根本不放置任何正确的="true" 属性或将其用于多项选择。
我不希望用户能够做的示例如下:
没有正确的选择(不要让用户这样做)
<MultipleChoice>
<Choices>
<Choice>a) apple</Choice>
<Choice>b) banana</Choice>
<Choice>c) grapes</Choice>
</Choices>
</MultipleChoice>
多项正确选择(不要让用户这样做)
<MultipleChoice>
<Choices>
<Choice>a) apple</Choice>
<Choice correct="true">b) banana</Choice>
<Choice correct="true">c) grapes</Choice>
</Choices>
</MultipleChoice>
如何限制我的架构的用户能够定义一个且只有一个正确的选择?我的意思是,如果他们违反了唯一一个正确答案规则,我应该能够给他们一个错误。
这是我当前的架构
...
<xs:complexType name="MultipleChoice">
<xs:complexContent>
<xs:element name="Choices" type="Choices" minOccurs="1" maxOccurs="1"/>
</xs:complexContent>
</xs:complexType>
<xs:complexType name="Choices">
<xs:sequence>
<xs:element name="Choice" type="Choice" maxOccurs="unbounded" minOccurs="1"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="Choice">
<xs:simpleContent>
<xs:extension base="xs:string">
<xs:attribute name="correct" type="xs:boolean" default="false"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
【问题讨论】:
-
我很想说所有足够有趣的问题都有不止一个正确答案...
标签: xml xsd schema processor multiple-choice