473,320 Members | 1,831 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

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 2437
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
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...
1
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...
4
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"/>...
2
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
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...
2
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...
2
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
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...
0
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">...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.