Defining mixed element in XSD 1.0 allowing “nesting”

I am facing the following problem. I need to create an XSD schema of my XML file. Let’s say that I have several “Conversation Objects” nodes:

  • Message
  • End
  • YesOrNoAnswer

which are simple elements (or almost) that I am able to describe in my XSD. For example my End node is defined in this way:

<xs:element name="END" type="EndType"/>

<xs:complexType name="EndType" />
    <xs:attribute name="completedMission" type="xs:string"/>
    <xs:attribute name="retry" type="xs:boolean"/>
</xs:complexType>

Then I have a special one called:

  • multipleChoice

This kind of element has the following structure:

<multipleChoice actor="" numberOfChoices="" percentage=""> message text

    <choice>
        <effects name="" bar="" points="" action="" likelihood="" />
        ...
    </choice>

    <choice>
       <effects name="" bar="" points="" action="" likelihood="" />
       ...
    </choice>

    <choice>
       <effects name="" bar="" points="" action="" likelihood="" />
       ...
    </choice>

</multipleChoice>

So, the first problem is:

  • there have to be the same number of “choice” nodes as defined in the “numberOfChoices” attribute
  • the “choice” node has to be followed by the “effect” node, which is just containing some attributes
  • after the “effect” node any other kind of node can be inserted, without any order and as many times as we want. For example any of the simple ones (Message, End, YesOrNoAnswer) or “multipleChoice” nodes, allowing nesting in as many level of depth as we want.

How can I define the “multipleChoice” node in XSD (including attributes, text, “choice” and “effect” nodes) ? Thanks in advance!


Source: xml

Leave a Reply