473,548 Members | 2,683 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Help -- xs:Choice minOccurs not being enforced!

I have the following schema designed:

<xs:complexTy pe name="AzzFeatur e-BoxType" mixed="true">
<xs:choice minOccurs="1" maxOccurs="unbo unded">
<xs:element ref="Sub-Head" minOccurs="1" maxOccurs="unbo unded"/>
<xs:element ref="Title-Text" minOccurs="0" maxOccurs="unbo unded"/>
<xs:element ref="Text" minOccurs="0" maxOccurs="unbo unded"/>
<xs:element ref="Link-List" minOccurs="0" maxOccurs="unbo unded"/>
</xs:choice>
<xs:attribute name="axetype" type="xs:string " fixed="containe r"/>
</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="contai ner">
<Title-Text axetype="field" >Title</Title-Text>
</Feature-Box>
Any ideas?

Mar 21 '06 #1
7 2450
jkmyoung
2,057 Recognized Expert Top Contributor
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:complexTy pe name="AzzFeatur e-BoxType" mixed="true">
<xs:choice minOccurs="1" maxOccurs="unbo unded">
<xs:element ref="Sub-Head" minOccurs="1" maxOccurs="unbo unded"/>
<xs:element ref="Title-Text" minOccurs="0" maxOccurs="unbo unded"/>
<xs:element ref="Text" minOccurs="0" maxOccurs="unbo unded"/>
<xs:element ref="Link-List" minOccurs="0" maxOccurs="unbo unded"/>
</xs:choice>
<xs:attribute name="axetype" type="xs:string " fixed="containe r"/>
</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="contai ner">
<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="unbo unded"/>
<xs:element ref="Title-Text" minOccurs="0" maxOccurs="unbo unded"/>
<xs:element ref="Text" minOccurs="0" maxOccurs="unbo unded"/>
<xs:element ref="Link-List" minOccurs="0" maxOccurs="unbo unded"/>

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="unbo unded"/>
<xs:element ref="Title-Text" minOccurs="0" maxOccurs="unbo unded"/>
<xs:element ref="Text" minOccurs="0" maxOccurs="unbo unded"/>
<xs:element ref="Link-List" minOccurs="0" maxOccurs="unbo unded"/>


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=unbou nded 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="unbo unded">
<xs:element name="name1" type="type1"/>
<xs:element name="name2" type="type2"/>
</xs:choice>
</xs:sequence>
<!-- define complex types -->
<xs:complexTy pe name="type1">
<xs:sequence>
<xs:element ref="Sub_Head" minOccurs="1" maxOccurs="unbo unded"/>
</xs:sequence>
</xs:complexType>

<xs:complexTy pe name="type2">
<xs:choice minOccurs="0" maxOccurs="unbo unded">
<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=unbou nded 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="unbo unded">
<xs:element name="name1" type="type1"/>
<xs:element name="name2" type="type2"/>
</xs:choice>
</xs:sequence>
<!-- define complex types -->
<xs:complexTy pe name="type1">
<xs:sequence>
<xs:element ref="Sub_Head" minOccurs="1" maxOccurs="unbo unded"/>
</xs:sequence>
</xs:complexType>

<xs:complexTy pe name="type2">
<xs:choice minOccurs="0" maxOccurs="unbo unded">
<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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
510
by: dgaucher | last post by:
Hi, I want to consume a Web Service that returns a choice, but my C++ client always receives the same returned type. On the other hand, when I am using a Java client, it is working fine (of course, the generated proxy is not the same). When I am looking at the C++ generated code, it seems fine, but when I am executing the code, I always...
1
2905
by: Oleg Ogurok | last post by:
Hi all, I have a complex type defined as follows: <xs:complexType name="SchedulingMethodType"> <xs:choice maxOccurs="1"> <xs:element name="Interval" type="xs:duration" /> <xs:element name="DailyAt" type="xs:duration" /> </xs:choice> </xs:complexType>
4
1713
by: Sergey Poberezovskiy | last post by:
Hi, As part of my schema I need to ensure that at least one of two fields have values. I defined my schema as follows: .... <xs:choice> <xs:element ref="el1"/> <xs:element ref="el2"/> <xs:sequence> <xs:element ref="el1"/>
2
4338
by: Sergey Poberezovskiy | last post by:
Hi, If I define my schema as <xs:choice> <xs:sequence> <xs:element ref="el_1" /> <xs:element ref="el_2" /> </xs:sequence> <xs:sequence>
2
5640
by: pawel.pabich | last post by:
Hajo, I know only one way of forcing element to have one or more childes: <xs:element name="saleOrSupplyMethod"> <BR/> <xs:complexType> <xs:choice> <xs:sequence> <xs:element name="generalSale" type="emptyTagType" /> <xs:element name="prescription" type="emptyTagType"/>
2
1659
by: hooomee | last post by:
Given: <xs:choice maxOccurs=5> <xs:element name="Foo" type="bar" /> <xs:element name="Foo1" type="bar" /> <xs:element name="Foo2" type="bar" /> </xs:choice> Is the choice made once and then the choosen element can occur 5 times, or is the choice made once for each occurance?
2
1343
by: cmay | last post by:
I am beginning to wonder if it is not possible to get this working. I am trying to do: <root> <a/> <b/> <c/> </root>
0
2128
by: =?Utf-8?B?RGFtaWFu?= | last post by:
(This is using .net version 2.0.50727 and system.xml 2.0.50727.42) I am getting an error when serializing using classes generated by xsd.exe. The error is of the type "The Type <typewas not expected. Use the XmlInclude or SoapInclude etc" This error is appearing sprodically, with no obvious pattern. When it occurs, it happens every...
0
2829
by: Peter Larsen | last post by:
Is this really a valid schema design? <?xml version="1.0" encoding="UTF-8"?> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified"> <xs:element name="root"> <xs:complexType> <xs:sequence> <xs:choice> <xs:element name="e1" minOccurs="0" />
0
7512
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7707
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7951
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7466
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
6036
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
5082
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3475
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1926
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1051
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.