简体   繁体   English

如何包含同名的多个元素

[英]How to include multiple elements of the same name

I try to create an XML to describe exercises with multiple choice options or just plain text. 我尝试创建一个XML来描述带有多项选项或纯文本的练习。 The XML could look like this: XML可能如下所示:

<exercise number="1" type="multiChoice">
<question>My very importand question</question>
<answer type="false">yes</answer>
<answer type="true">no</answer>

<exercise number="2" type="text">
    <question>Question 2</question>
    <answer>the right answer</answer>
</exercise>

So I tried to use a sequence for the answer, which didnt work if I try to validate it when I'm having more than one of the <answer> -Tags in the XML. 所以我尝试使用一个序列作为答案,如果我在XML中有多个<answer> -Tags时尝试验证它,它就无法工作。

This is the Schema: 这是Schema:

    <xs:complexType name="exerciseType">
    <xs:sequence>
        <xs:element name="question" type="questionType"/>
        <xs:sequence>
            <xs:element name="answer" minOccurs="1">
                <xs:complexType>
                    <xs:simpleContent>
                        <xs:extension base="xs:string">
                            <xs:attribute name="type" type="xs:boolean" use="optional"/>
                        </xs:extension>
                    </xs:simpleContent>
                </xs:complexType>
            </xs:element>
        </xs:sequence>
    </xs:sequence>
    <xs:attribute name="number" type="xs:positiveInteger"/>
    <xs:attribute name="type" type="xs:string"/>
</xs:complexType>

Anyone knows what is wrong with my schema? 任何人都知道我的架构有什么问题?

Thanks in advance! 提前致谢!

You could try to set maxOccurs attribute: 您可以尝试设置maxOccurs属性:

<xs:complexType name="exerciseType">
    <xs:sequence>
        <xs:element name="question" type="questionType"/>
        <xs:element name="answer" maxOccurs="unbounded">
    </xs:sequence>
    <xs:attribute name="number" type="xs:positiveInteger"/>
    <xs:attribute name="type" type="xs:string"/>
</xs:complexType>

Disclaimer: this was written without being validated by a tool and can contain bugs. 免责声明:这是在未经工具验证的情况下编写的,可能包含错误。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM