Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > xsd puzzler

Reply
Thread Tools

xsd puzzler

 
 
Anon
Guest
Posts: n/a
 
      10-21-2003
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!
 
Reply With Quote
 
 
 
 
Patrick TJ McPhee
Guest
Posts: n/a
 
      10-21-2003
In article <3f951b64$0$194$(E-Mail Removed)>,
Anon <(E-Mail Removed)> 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
http://www.velocityreviews.com/forums/(E-Mail Removed)
 
Reply With Quote
 
 
 
 
Bob Foster
Guest
Posts: n/a
 
      10-22-2003
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" <(E-Mail Removed)> wrote in message
news:3f951b64$0$194$(E-Mail Removed)...
> 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!



 
Reply With Quote
 
Pete
Guest
Posts: n/a
 
      10-27-2003
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!
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Wireless puzzler...NIC will send, *not* receive intrepid_dw@hotmail.com Wireless Networking 5 06-14-2006 03:39 PM
WEP connection puzzler gromit12@gmail.com Wireless Networking 3 04-18-2006 11:28 PM
Tkinter Puzzler Tim Daneliuk Python 4 01-07-2005 11:28 AM
dropdown puzzler Jim Corey ASP .Net 1 01-16-2004 03:25 AM
odd image puzzler Richard HTML 10 01-04-2004 09:51 PM



Advertisments