Reputation: 401
I try to create an XML to describe exercises with multiple choice options or just plain text. The XML could look like this:
<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.
This is the 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!
Upvotes: 0
Views: 102
Reputation: 3214
You could try to set maxOccurs
attribute:
<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.
Upvotes: 2