By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
431,745 Members | 1,897 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 431,745 IT Pros & Developers. It's quick & easy.

Help -- xs:Choice minOccurs not being enforced!

P: n/a
I have the following schema designed:

<xs:complexType name="AzzFeature-BoxType" mixed="true">
<xs:choice minOccurs="1" maxOccurs="unbounded">
<xs:element ref="Sub-Head" minOccurs="1" maxOccurs="unbounded"/>
<xs:element ref="Title-Text" minOccurs="0" maxOccurs="unbounded"/>
<xs:element ref="Text" minOccurs="0" maxOccurs="unbounded"/>
<xs:element ref="Link-List" minOccurs="0" maxOccurs="unbounded"/>
</xs:choice>
<xs:attribute name="axetype" type="xs:string" fixed="container"/>
</xs:complexType>
However it is NOT enforcing that one "Sub-Head" is added. Ex: below is
valid XML against the above schema
<Feature-Box axetype="container">
<Title-Text axetype="field">Title</Title-Text>
</Feature-Box>
Any ideas?

Mar 21 '06 #1
Share this Question
Share on Google+
7 Replies


jkmyoung
Expert 100+
P: 2,057
I think it IS being enforced. It's simply choosing type Title-Text, and then using the minoccurs=0 of that.

I think you want <xs:sequence> instead of choice.
Mar 21 '06 #2

P: n/a
rb*******@gmail.com wrote:
I have the following schema designed:

<xs:complexType name="AzzFeature-BoxType" mixed="true">
<xs:choice minOccurs="1" maxOccurs="unbounded">
<xs:element ref="Sub-Head" minOccurs="1" maxOccurs="unbounded"/>
<xs:element ref="Title-Text" minOccurs="0" maxOccurs="unbounded"/>
<xs:element ref="Text" minOccurs="0" maxOccurs="unbounded"/>
<xs:element ref="Link-List" minOccurs="0" maxOccurs="unbounded"/>
</xs:choice>
<xs:attribute name="axetype" type="xs:string" fixed="container"/>
</xs:complexType>
However it is NOT enforcing that one "Sub-Head" is added. Ex: below is
valid XML against the above schema
<Feature-Box axetype="container">
<Title-Text axetype="field">Title</Title-Text>
</Feature-Box>
Any ideas?


The problem is you are using xs:choice and so it doesn't have to occur
at all. If you want them all to occur use either xs:sequence, or xs:all
or restructure the problem

Steve
Mar 21 '06 #3

P: n/a
gotcha, but the problem with xs:sequence and xs:all is they enforce
order.

I needed the following to be allowed in any order in the XML

<xs:element ref="Sub-Head" minOccurs="1" maxOccurs="unbounded"/>
<xs:element ref="Title-Text" minOccurs="0" maxOccurs="unbounded"/>
<xs:element ref="Text" minOccurs="0" maxOccurs="unbounded"/>
<xs:element ref="Link-List" minOccurs="0" maxOccurs="unbounded"/>

Mar 21 '06 #4

P: n/a
rb*******@gmail.com wrote:
gotcha, but the problem with xs:sequence and xs:all is they enforce
order.

I needed the following to be allowed in any order in the XML

<xs:element ref="Sub-Head" minOccurs="1" maxOccurs="unbounded"/>
<xs:element ref="Title-Text" minOccurs="0" maxOccurs="unbounded"/>
<xs:element ref="Text" minOccurs="0" maxOccurs="unbounded"/>
<xs:element ref="Link-List" minOccurs="0" maxOccurs="unbounded"/>


Are you entirely sure this is the data structure you want though? It
seems a bit strange to me to insist that they can occur in any order but
that they can occur as many time as they like as well?
You could always sort of nested choice loops if you get what i mean?

Steve
Mar 21 '06 #5

P: n/a
The schema is for a custom CMS and each element is sort of a "Page
Part". So the requirement is the following

"Feature-Box" page part can have any order of the following sub page
parts
Sub-Head (Min: 1, Max: unlimited)
Title-Text (Min: 0, Max: unlimited)
Text (Min: 0, Max: unlimited)
Link-List (Min: 0, Max: unlimited)

How would I write the "nested choice loop"?

Thanks in advance for you help!
Ryan

Mar 21 '06 #6

P: n/a
rb*******@gmail.com wrote:
The schema is for a custom CMS and each element is sort of a "Page
Part". So the requirement is the following

"Feature-Box" page part can have any order of the following sub page
parts
Sub-Head (Min: 1, Max: unlimited)
Title-Text (Min: 0, Max: unlimited)
Text (Min: 0, Max: unlimited)
Link-List (Min: 0, Max: unlimited)

How would I write the "nested choice loop"?

Thanks in advance for you help!
Ryan


Ok, well if you deal with the Sub-Head element separately by placing
that within a sequence by itself with minOccurs=1 and
maxOccurs=unbounded and then place the other 3 elements within a choice
which has minOccurs = 0 and maxOccurs = unbounded

Something like this:

<xs:sequence>
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:element name="name1" type="type1"/>
<xs:element name="name2" type="type2"/>
</xs:choice>
</xs:sequence>
<!-- define complex types -->
<xs:complexType name="type1">
<xs:sequence>
<xs:element ref="Sub_Head" minOccurs="1" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>

<xs:complexType name="type2">
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:element ref="Title_Text"/>
<xs:element ref="Text"/>
<xs:element ref="Link_List"/>
</xs:choice>
</xs:complexType>
I should say though that that is just off the top of my head and I
haven't checked it or anything cos by computers being a dog at the
moment so I can't guarantee it's even correct!! ;-) I think you're
looking for something along those lines though.

Steve

Mar 22 '06 #7

P: n/a
Stephen Marjoribanks wrote:
rb*******@gmail.com wrote:
The schema is for a custom CMS and each element is sort of a "Page
Part". So the requirement is the following

"Feature-Box" page part can have any order of the following sub page
parts
Sub-Head (Min: 1, Max: unlimited)
Title-Text (Min: 0, Max: unlimited)
Text (Min: 0, Max: unlimited)
Link-List (Min: 0, Max: unlimited)

How would I write the "nested choice loop"?

Thanks in advance for you help!
Ryan


Ok, well if you deal with the Sub-Head element separately by placing
that within a sequence by itself with minOccurs=1 and
maxOccurs=unbounded and then place the other 3 elements within a choice
which has minOccurs = 0 and maxOccurs = unbounded

Something like this:

<xs:sequence>
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:element name="name1" type="type1"/>
<xs:element name="name2" type="type2"/>
</xs:choice>
</xs:sequence>
<!-- define complex types -->
<xs:complexType name="type1">
<xs:sequence>
<xs:element ref="Sub_Head" minOccurs="1" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>

<xs:complexType name="type2">
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:element ref="Title_Text"/>
<xs:element ref="Text"/>
<xs:element ref="Link_List"/>
</xs:choice>
</xs:complexType>
I should say though that that is just off the top of my head and I
haven't checked it or anything cos by computers being a dog at the
moment so I can't guarantee it's even correct!! ;-) I think you're
looking for something along those lines though.

Steve


Sorry I've just realised I've left the <sequence> tags around the first
<choice> tags, they shouldn't be there!

Steve
Mar 22 '06 #8

This discussion thread is closed

Replies have been disabled for this discussion.