pribeiro
pribeiro

Reputation: 1251

Schema Element definition with sub-elements in ANY order

I'm trying to create an element in a schema where its sub-types can appear in any order and as many times as necessary:

    <xs:element name="workflowNodes">
    <xs:complexType>
        <xs:sequence minOccurs="0" maxPO>
            <xs:element ref="nodeType1" />
            <xs:element ref="nodeType2" />
            <xs:element ref="nodeType3" />
            <xs:element ref="nodeType4" />
        </xs:sequence>
    </xs:complexType>
</xs:element>

where the nodes nodeType(n) can be in any order and be repetitive as necessary.

Also, I tried :

But the compiler is not working complaining the nodeType2 is not valid when there is not nodeType1.

What am I missing here?

Thanks in advance.

Upvotes: 0

Views: 434

Answers (1)

marc_s
marc_s

Reputation: 754220

You should be able to get your results by doing this:

<xs:element name="workflowNodes">
        <xs:complexType>
                <xs:choice minOccurs="0" maxOccurs="unbounded">
                        <xs:element ref="nodeType1" />
                        <xs:element ref="nodeType2" />
                        <xs:element ref="nodeType3" />
                        <xs:element ref="nodeType4" />
                </xs:choice>
        </xs:complexType>
</xs:element>

<xs:choice> gives you the option to pick one of the elements, and making the xs:choice appear many times allows you to pick each element as many times as you like.

Marc

Upvotes: 2

Related Questions