473,908 Members | 4,445 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

xs:choice

Hi all,

I have a complex type defined as follows:

<xs:complexTy pe name="Schedulin gMethodType">
<xs:choice maxOccurs="1">
<xs:element name="Interval" type="xs:durati on" />
<xs:element name="DailyAt" type="xs:durati on" />
</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.Con straintExceptio n Failed to enable constraints.
It seems the framework tries to load both values. So when I use something
like this:

<SchedulingMeth od>
<Interval>PT30M </Interval>
</SchedulingMetho d>

The error tells that value DailyAt is missing (i.e. it throws
InvalidCastExce ption 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 2922
Hi Oleg,

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

<xs:complexTy pe name="Schedulin gMethodType">
<xs:choice minOccurs="1" maxOccurs="1">
<xs:element name="Interval" type="xs:durati on" minOccurs="0"
maxOccurs="1" />
<xs:element name="DailyAt" type="xs:durati on" 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
"AllowDBNul l" both set to True. Without setting minOccurs to 0 (zero), the
"allowNull" and "AllowDBNul l" 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.co m.ihatespammers .ireallydo.co> wrote in message
news:10******** *****@corp.supe rnews.com...
Hi all,

I have a complex type defined as follows:

<xs:complexTy pe name="Schedulin gMethodType">
<xs:choice maxOccurs="1">
<xs:element name="Interval" type="xs:durati on" />
<xs:element name="DailyAt" type="xs:durati on" />
</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.Con straintExceptio n Failed to enable constraints. It seems the framework tries to load both values. So when I use something
like this:

<SchedulingMeth od>
<Interval>PT30M </Interval>
</SchedulingMetho d>

The error tells that value DailyAt is missing (i.e. it throws
InvalidCastExce ption 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
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 get the first choice type.
4
1738
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
4359
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
5667
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"/>
7
2463
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" 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...
2
1681
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
1358
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
2147
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 time we run the code, however changes to our code in creating the objects before they are serialized...
0
2849
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
10029
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 usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9875
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
11334
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. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10529
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
8092
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7240
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 into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
6131
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4762
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
3
3352
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.