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

Problem in XSD.EXE handling Multidimensional XmlArrays

Hi,

This issue is related to System.Xml.Serialization.XmlElementArrayAttribute
class.

We are using VS.NET 2005 (RTM) Professional Edition version 8.0.50727.42
(RTM.050727-4200).
-----------------------------------------------------------------------
Consider the following XSD:
-----------------------------------------------------------------------
<?xml version="1.0" encoding="utf-8"?>
<xs:schema id="result" xmlns="" xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xs:element name="choice" nillable="true">
<xs:complexType>
<xs:simpleContent msdata:ColumnName="choice_Text" msdata:Ordinal="0">
<xs:extension base="xs:string">
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:element>
<xs:element name="result" msdata:IsDataSet="true"
msdata:UseCurrentLocale="true">
<xs:complexType>
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:element ref="choice" />
<xs:element name="video_template">
<xs:complexType>
<xs:sequence>
<xs:element name="laserdisk_stock" type="xs:string"
minOccurs="0" />
<xs:element name="user_rating" minOccurs="0"
maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element ref="choice" minOccurs="0"
maxOccurs="unbounded" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:choice>
</xs:complexType>
</xs:element>
</xs:schema>

-----------------------------------------------------------------------
Importing this XSD using XSD.EXE generates the following CS file:
(comments removed for brevity)
---------------------------------------------------------------------------
using System.Xml.Serialization;

[System.CodeDom.Compiler.GeneratedCodeAttribute("xs d", "2.0.50727.42")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("c ode")]
[System.Xml.Serialization.XmlTypeAttribute(Anonymou sType=true)]
[System.Xml.Serialization.XmlRootAttribute(Namespac e="", IsNullable=true)]
public partial class choice {

[System.Xml.Serialization.XmlTextAttribute()]
public string Value;
}

[System.CodeDom.Compiler.GeneratedCodeAttribute("xs d", "2.0.50727.42")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("c ode")]
[System.Xml.Serialization.XmlTypeAttribute(Anonymou sType=true)]
[System.Xml.Serialization.XmlRootAttribute(Namespac e="", IsNullable=false)]
public partial class result {

[System.Xml.Serialization.XmlElementAttribute("choi ce", typeof(choice),
IsNullable=true)]
[System.Xml.Serialization.XmlElementAttribute("vide o_template",
typeof(resultVideo_template),
Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
public object[] Items;
}

[System.CodeDom.Compiler.GeneratedCodeAttribute("xs d", "2.0.50727.42")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("c ode")]
[System.Xml.Serialization.XmlTypeAttribute(Anonymou sType=true)]
public partial class resultVideo_template {
[System.Xml.Serialization.XmlElementAttribute(Form= System.Xml.Schema.XmlSchemaForm.Unqualified)]
public string laserdisk_stock;
[System.Xml.Serialization.XmlArrayAttribute(Form=Sy stem.Xml.Schema.XmlSchemaForm.Unqualified)]
[System.Xml.Serialization.XmlArrayItemAttribute("ch oice", typeof(choice))]
public choice[][] user_rating;
}

-----------------------------------------------------------------------
Trying to serialize an object of type "result" into an Xml file using the
XmlSerializer Class causes an exception to occur at the following code:

XmlSerializer xmlSer = new XmlSerializer(typeof(result));
-----------------------------------------------------------------------
Exception:
Error while creating XmlSerializer object.
Unable to generate a temporary class (result=1).
error CS0030: Cannot convert type 'choice[]' to 'choice'
error CS0029: Cannot implicitly convert type 'choice' to 'choice[]'

-----------------------------------------------------------------------
Our Analysis:
-----------------------------------------------------------------------

When we try to serialize type result, the XmlSerializer gets
an ambiguous match between choice and resultVideo_template.user_rating while
creating the XmlSerializer object.

To disambiguate the XmlSerializer we have to correctly specify (since
user_rating field is of type choice[][]) that a single element of this type
is "choice[]" instead of "choice". This issue exists with all multi-
dimensional arrays.

This should have been correctly generated by XSD.EXE.

-----------------------------------------------------------------------

Thanks in advance.
Kapil
(Persistent Systems Pvt. Ltd.)
Jan 30 '06 #1
0 3767

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Brian | last post by:
I have an array like this: $events = array( array( '2003-07-01', 'Event Title 1', '1' //ID Number (not unique) ), array( '2003-07-02',
9
by: Georg Ringer | last post by:
Hi, I've got a multidimensional array which looks like this: $data = array('nname' => 'Auerbach', 'vname' => 'Berthold', 'uid' => 20); $data = array('nname' => 'Bloch', 'vname' => 'Ernst', 'uid'...
9
by: Kathryn | last post by:
Hiya I have a problem with using some client side and server side scripting together in an ASP. I'm using VBScript. What I'm trying to achieve is this - - Page loads up and some server side...
2
by: Ivan | last post by:
In my HTML forms (created by PHP) for attribute names I have been using multidimensional arrays as illustrated in the following: <table> <tr> <td> ID </td> <td> <input TYPE=hidden Name=frm_s...
1
by: Mark Smith | last post by:
I'm trying to copy data from a 1D array to a 2D array. The obvious thing doesn't work: int twoDee = new int; int oneDee = new int { 1, 2 }; Array.Copy(oneDee, 2, twoDee, 2, 2); This causes a...
5
by: Chris Lee | last post by:
I have a vexing problem with an object of multidimensional array. The function I call (an external com function) is supposed to return a 2-D array that looks like this: (0,0), (1,0) ......, (n,0)....
2
by: BB | last post by:
Hello, I have a HTML form containing multidimensional selects listing equipments and their quantitites. This allow the users to select the kind of equipment and quantitites they would like to...
11
by: Bigshot | last post by:
Im trying to scan a file using fscanf and want to put the results in a multidimensional array (since C has no strings I need it to store names). Basically I want to be able to have a...
2
by: oopsatwork | last post by:
Ok...so, I have been outside of the C world for a _very_ long time...but not so long as to remember how to do multidimensional arrays. So, let me state that I know how to malloc pointers to...
9
by: Slain | last post by:
I need to convert a an array to a multidimensional one. Since I need to wrok with existing code, I need to modify a declaration which looks like this In the .h file int *x; in a initialize...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
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
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,...
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,...

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.