473,593 Members | 2,858 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 2908
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
1716
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
4344
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
5646
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
2454
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
1663
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
1346
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
2132
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
2831
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
7871
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
8227
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...
0
6642
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
5735
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
5400
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
3851
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2379
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
1
1467
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1202
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.