473,396 Members | 1,756 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,396 software developers and data experts.

xsd puzzler

Hi,

Having trouble creating a schema. I want the following chunks xml to be
acceptable

<a>
<b .... />
</a>

...or...

<a>
<c .... />
</a>

So element a can can have sub-elements b or c.

Constraints are: (1) a must have one of b or c, (2) a may only have one
of b or c.

The current schema I've got is as follows:

<xs:choice maxOccurs="1" minOccurs="1">
<xs:element name="b" type="typeB" minOccurs="0"/>
<xs:element name="c" type="typeC" minOccurs="0"/>
</xs:choice>

However, although this schema satisfies constraint (2), it allows me to
create element <a> without any sub-elements. In other words, the
minOccurs of the choice is being ignored.

Can anyone suggest an alternate approach?

If it makes any difference I'm using XML Spy to create all of this, and
will deploy to the MS Xml parser (whatever version is latest).

TIA,
Pete

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 20 '05 #1
3 1323
In article <3f*********************@news.frii.net>,
Anon <an*******@devdex.com> wrote:

% Having trouble creating a schema. I want the following chunks xml to be
% acceptable
%
% <a>
% <b .... />
% </a>
%
% ..or...
%
% <a>
% <c .... />
% </a>

[...]

% The current schema I've got is as follows:
%
% <xs:choice maxOccurs="1" minOccurs="1">
% <xs:element name="b" type="typeB" minOccurs="0"/>
% <xs:element name="c" type="typeC" minOccurs="0"/>
% </xs:choice>

So, why do you have minOccurs set to 0? If you just use the
default values of minOccurs and maxOccurs, this should do
exactly what you want.
--

Patrick TJ McPhee
East York Canada
pt**@interlog.com
Jul 20 '05 #2
Remove the two minOccurs="0" as previously suggested.

minOccurs="1" maxOccurs="1" on the choice (which, by the way, is the
default) does not mean, as you may think, that the choice is constrained to
output exactly one element, it means the choice is not optional. But the
absence of any child elements matches both alternatives, so it is accepted.

Maybe the XML syntax is confusing. If you wrote (b?|c?) I don't think you'd
be surprised if it allowed no elements. Anyway, you shouldn't be.

Bob Foster

"Anon" <an*******@devdex.com> wrote in message
news:3f*********************@news.frii.net...
Hi,

Having trouble creating a schema. I want the following chunks xml to be
acceptable

<a>
<b .... />
</a>

..or...

<a>
<c .... />
</a>

So element a can can have sub-elements b or c.

Constraints are: (1) a must have one of b or c, (2) a may only have one
of b or c.

The current schema I've got is as follows:

<xs:choice maxOccurs="1" minOccurs="1">
<xs:element name="b" type="typeB" minOccurs="0"/>
<xs:element name="c" type="typeC" minOccurs="0"/>
</xs:choice>

However, although this schema satisfies constraint (2), it allows me to
create element <a> without any sub-elements. In other words, the
minOccurs of the choice is being ignored.

Can anyone suggest an alternate approach?

If it makes any difference I'm using XML Spy to create all of this, and
will deploy to the MS Xml parser (whatever version is latest).

TIA,
Pete

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Jul 20 '05 #3
My code now works, and my understanding of MinOccurs has been increased.

Thanks for your advice.

Pete
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 20 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Tim Daneliuk | last post by:
I am trying to initialize a menu in the following manner: for entry in : func = entry UI.ShortBtn.menu.add_command(label=entry, command=lambda: func(None)) However, at runtime, each of the...
5
by: Paul Rubin | last post by:
I have a gui with a bunch of buttons, labels, the usual stuff. It uses the grid manager: gui = Frame() gui.grid() gui.Label(....).grid() # put some widgets into the gui ... # more widgets...
5
by: Haines Brown | last post by:
I want a centered body, 680px wide, having a red bottom margin. The following works well in galeon, but not in IE5, where the bottom margin steals the full width of the viewpoint. That is, the red...
7
by: pseudonym | last post by:
To keep this short, assume the function working_test() works perfectly (because it does), while failing_test() is not. My GetCodec function returns a Stream (CryptoStream) object wrapped around...
0
by: Robert Harty | last post by:
Hello all, I have a strange problem with a HtmlTable control, which is dynamically created based on the results of a query. Each row in the table has a LinkButton added to it. When I create...
1
by: kscdavefl | last post by:
I am using the following code for a datagrid: DataView dv = CreateAppPermissionDataSource(); for (int i = 0; i < dv.Count; i++) { if (dv.Row.ToString() == "0") { dv.Row = "NO"; }
1
by: Jim Corey | last post by:
I'm thinking this problem is not specific to ASP.NET but anyway: I have a dropdown that I populate when the page loads, and I have values that are different from the text that displays, so the...
1
by: Dave | last post by:
Here's a question for you all. 1. I have in my application a control named CommonControl. CommonControl is inherited by a number of other controls in order to create semi-polymorphic controls. ...
5
by: kk_oop | last post by:
I'm having an inheritance problem. My mom says she just won't leave me her Three Stooges DVD collection when she's gone. Okay, just a bit of OO levity. Here's the real problem: We have...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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,...
0
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...
0
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,...

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.