Click to See Complete Forum and Search --> : Occurs in XML Schema


jamesm6162
01-06-2008, 11:23 AM
Hi

I have a specific structure to validate (shown below). However I need the element 1, 2, and 3 to appear in any order, any amount of times.

Should I use the <all> tag and add a maxOccurs as unbounded for it?

I'm not really sure if I can add the Occurrence constraints to anything but the <xsd:element> elements. Please help


<root>
<level1>
<element1 />
<element2 />
<element3 />
</level1>
</root>

moxol
01-06-2008, 12:18 PM
You can't do that with <all> tag because then maxOccurs attribute maximum value is 1. With <all> tag you can add elements without order but they must appear 0 or 1 time only.

jamesm6162
01-06-2008, 12:22 PM
okay so any suggestions?

moxol
01-06-2008, 12:37 PM
I am not sure that you can do what you want to do.

Only thing that I can think of right now is that you declare all those elements as global.


<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">

<xsd:element name="root"/>

<xsd:element name="level1"/>
<xsd:element name="element1"/>
<xsd:element name="element2"/>
<xsd:element name="element3"/>


</xsd:schema>

jamesm6162
01-06-2008, 01:18 PM
okay I found the answer.

I should have a <choice> element with maxOccurs set to unbounded.

eg:

<xs:element name="level1">
<xs:complexType>
<xs:choice maxOccurs="unbounded">
...then the three elements
</xs:choice>
</xscomplexType>
</xs:element

moxol
01-06-2008, 03:12 PM
Yes, that works, nice solution. I didn't thought of that.