469,568 Members | 1,506 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,568 developers. It's quick & easy.

Help -- xs:Choice minOccurs not being enforced!

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
7 2238
jkmyoung
2,057 Expert 2GB
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
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
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
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
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
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
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.

Similar topics

1 post views Thread by Oleg Ogurok | last post: by
4 posts views Thread by Sergey Poberezovskiy | last post: by
2 posts views Thread by Sergey Poberezovskiy | last post: by
2 posts views Thread by hooomee | last post: by
reply views Thread by =?Utf-8?B?RGFtaWFu?= | last post: by
reply views Thread by Peter Larsen | last post: by
reply views Thread by suresh191 | last post: by
4 posts views Thread by guiromero | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.