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

xs:choice

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>

When I use this type in XML, I want to specify either <Interval> or
<DailyAt> but not both, hence the use of <xs:choice>. However, when I create
a DataSet generated by VS.NET 2003, and try to load my XML file with
..Read(), I get System.Data.ConstraintException Failed to enable constraints.
It seems the framework tries to load both values. So when I use something
like this:

<SchedulingMethod>
<Interval>PT30M</Interval>
</SchedulingMethod>

The error tells that value DailyAt is missing (i.e. it throws
InvalidCastException trying to convert null into TimeSpan).

Am I doing something wrong? Doesn't <xs:choice> mean "only one from the
list" ?

Thanks in advance,

-Oleg.
Nov 12 '05 #1
1 2897
Hi Oleg,

I have to admit, I stared at this for a while without seeing it, but the
solution is fairly simple.

<xs:complexType name="SchedulingMethodType">
<xs:choice minOccurs="1" maxOccurs="1">
<xs:element name="Interval" type="xs:duration" minOccurs="0"
maxOccurs="1" />
<xs:element name="DailyAt" type="xs:duration" minOccurs="0"
maxOccurs="1" />
</xs:choice>
</xs:complexType>

Notice the minOccurs attribute for the Interval and DailyAt elements inside
the choice element. When you load this schema into a dataset, the column
definitions in the table will be specified with "allowNull" and
"AllowDBNull" both set to True. Without setting minOccurs to 0 (zero), the
"allowNull" and "AllowDBNull" properties are set to false.

I hope this helps.

Brooks
[MSFT]
--
This posting is provided "AS IS" with no warranties, and confers no rights.
Use of included script samples are subject to the terms specified at
http://www.microsoft.com/info/copyright.htm.

"Oleg Ogurok" <ol**@ogurok.com.ihatespammers.ireallydo.co> wrote in message
news:10*************@corp.supernews.com...
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>

When I use this type in XML, I want to specify either <Interval> or
<DailyAt> but not both, hence the use of <xs:choice>. However, when I create a DataSet generated by VS.NET 2003, and try to load my XML file with
.Read(), I get System.Data.ConstraintException Failed to enable constraints. It seems the framework tries to load both values. So when I use something
like this:

<SchedulingMethod>
<Interval>PT30M</Interval>
</SchedulingMethod>

The error tells that value DailyAt is missing (i.e. it throws
InvalidCastException trying to convert null into TimeSpan).

Am I doing something wrong? Doesn't <xs:choice> mean "only one from the
list" ?

Thanks in advance,

-Oleg.

Nov 12 '05 #2

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...
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...
7
by: rbarschaw | last post by:
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"...
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: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
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: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
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)...
1
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...
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...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.