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

Deserializing xs:choice with xs:sequence problem

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>
<xs:element ref="el_3" />
<xs:element ref="el_4" />
<xs:element ref="el_5" />
</xs:sequence>
<xs:choice>

and compile it with .Net 2003 xsd.exe, then I receive only one

[ ... choice element attributes ..]
public string Item;
// with the choice type one of the following:
public enum ItemChoiceType
{ el_1, el_2, el_3, el_4, el_5 }

So instead of choosing between two sequences, XmlSerialiser chooses between
the first two elements in those sequences, and the rest is just ignored!!!

I NEED the rest as well.

Can anyone please point me in the right direction on how to read the rest of
the sequences?

Thanks in advance,

Sergey
Nov 12 '05 #1
2 4322
The .NET framework 2.0 behavior is better: It flattens the choice, but it
still allows you to create and read valid instances:

public partial class test {

/// <remarks/>

[System.Xml.Serialization.XmlElementAttribute("e1")]

[System.Xml.Serialization.XmlElementAttribute("e2")]

[System.Xml.Serialization.XmlElementAttribute("e3")]

[System.Xml.Serialization.XmlElementAttribute("e4")]

[System.Xml.Serialization.XmlElementAttribute("e5")]

[System.Xml.Serialization.XmlChoiceIdentifierAttrib ute("ItemsElementName")]

public string[] Items;

/// <remarks/>

[System.Xml.Serialization.XmlElementAttribute("Item sElementName")]

[System.Xml.Serialization.XmlIgnoreAttribute()]

public ItemsChoiceType[] ItemsElementName; }

"Sergey Poberezovskiy" <Se*****************@discussions.microsoft.com> wrote
in message news:D7**********************************@microsof t.com...
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>
<xs:element ref="el_3" />
<xs:element ref="el_4" />
<xs:element ref="el_5" />
</xs:sequence>
<xs:choice>

and compile it with .Net 2003 xsd.exe, then I receive only one

[ ... choice element attributes ..]
public string Item;
// with the choice type one of the following:
public enum ItemChoiceType
{ el_1, el_2, el_3, el_4, el_5 }

So instead of choosing between two sequences, XmlSerialiser chooses between the first two elements in those sequences, and the rest is just ignored!!!

I NEED the rest as well.

Can anyone please point me in the right direction on how to read the rest of the sequences?

Thanks in advance,

Sergey

Nov 12 '05 #2
Zafar,

Unfortunately I have to live with 1.1 - but changing

public string Item;
to
public string[] Items;

worked!!! - the only thing is that I will have to manually modify the
generated file every time I need to change my schema - a small price to pay.

Thanks again.

Sergey

"Zafar Abbas" wrote:
The .NET framework 2.0 behavior is better: It flattens the choice, but it
still allows you to create and read valid instances:

public partial class test {

/// <remarks/>

[System.Xml.Serialization.XmlElementAttribute("e1")]

[System.Xml.Serialization.XmlElementAttribute("e2")]

[System.Xml.Serialization.XmlElementAttribute("e3")]

[System.Xml.Serialization.XmlElementAttribute("e4")]

[System.Xml.Serialization.XmlElementAttribute("e5")]

[System.Xml.Serialization.XmlChoiceIdentifierAttrib ute("ItemsElementName")]

public string[] Items;

/// <remarks/>

[System.Xml.Serialization.XmlElementAttribute("Item sElementName")]

[System.Xml.Serialization.XmlIgnoreAttribute()]

public ItemsChoiceType[] ItemsElementName; }

"Sergey Poberezovskiy" <Se*****************@discussions.microsoft.com> wrote
in message news:D7**********************************@microsof t.com...
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>
<xs:element ref="el_3" />
<xs:element ref="el_4" />
<xs:element ref="el_5" />
</xs:sequence>
<xs:choice>

and compile it with .Net 2003 xsd.exe, then I receive only one

[ ... choice element attributes ..]
public string Item;
// with the choice type one of the following:
public enum ItemChoiceType
{ el_1, el_2, el_3, el_4, el_5 }

So instead of choosing between two sequences, XmlSerialiser chooses

between
the first two elements in those sequences, and the rest is just ignored!!!

I NEED the rest as well.

Can anyone please point me in the right direction on how to read the rest

of
the sequences?

Thanks in advance,

Sergey


Nov 12 '05 #3

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: 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"...
1
by: SL33PY | last post by:
Hi, I'm currently busy writing an xsd at one point in time i whish that my xml must look like: <object> <loc> <disk> <drive>c</drive> <path>temp\path</path> <files>*.*</files>...
1
by: Sjaakie | last post by:
Hi all, I used the xsd-util to turn the following XML-file into an .xsd and a class. <?xml version="1.0" encoding="utf-8" ?> <Settings> <ApplicationTitle>...</ApplicationTitle>...
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>
2
by: puffy | last post by:
Hi, Everyone! I'd need a little help. I understand this is not valid, but is there an (easy) way to make it valid? <xs:complexType name="control_Type"> <xs:sequence> <xs:element name="id"...
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: 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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
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...
0
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...

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.