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

Problems with deserializing XML

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>
<DebugEmail>...</DebugEmail>
<Proxy>
<Enabled>...</Enabled>
<Url>...</Url>
<Port>...</Port>
<Login>...</Login>
<Password>...</Password>
</Proxy>
<Feeds>
<Feed>
<Description>...</Description>
<Url>...</Url>
<DateTimeCorrection>...</DateTimeCorrection>
<RefreshInterval>...</RefreshInterval>
</Feed>
<Feed>
<Description>...</Description>
<Url>...</Url>
<DateTimeCorrection>...</DateTimeCorrection>
<RefreshInterval>...</RefreshInterval>
</Feed>
</Feeds>
</Settings>

But somehow I cannot use the output to deserialize the file. The VS2005
debugger throws the following message:

error CS0030: cannot convert type SettingsFeedsFeed[] to
SettingsFeedsFeed

I use this code to deserialize the file:
FileStream fs = new FileStream(@"Data\Settings.xml", FileMode.Open);
XmlSerializer serializer = new XmlSerializer(typeof(Settings));
settings = (Settings)serializer.Deserialize(fs);
Below are snippets of the generated cs file and the complete xsd.
Can you help me out?

*** .cs file ***

public partial class Settings {
...
[System.Xml.Serialization.XmlArrayAttribute(Form=Sy stem.Xml.Schema.XmlSchemaForm.Unqualified)]
[System.Xml.Serialization.XmlArrayItemAttribute("Fe ed",
typeof(SettingsFeedsFeed),
Form=System.Xml.Schema.XmlSchemaForm.Unqualified, IsNullable=false)]
public SettingsFeedsFeed[][] Feeds {
get {
return this.feedsField;
}
set {
this.feedsField = 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)]
public partial class SettingsFeedsFeed {

private string descriptionField;

private string urlField;

private string dateTimeCorrectionField;

private string refreshIntervalField;

[System.Xml.Serialization.XmlElementAttribute(Form= System.Xml.Schema.XmlSchemaForm.Unqualified)]
public string Description {
get {
return this.descriptionField;
}
set {
this.descriptionField = value;
}
}

...
}

*** .xsd file ***

<?xml version="1.0" encoding="utf-8"?>
<xs:schema id="NewDataSet" xmlns=""
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xs:element name="Settings">
<xs:complexType>
<xs:sequence>
<xs:element name="ApplicationTitle" type="xs:string"
minOccurs="0" />
<xs:element name="DebugEmail" type="xs:string" minOccurs="0" />
<xs:element name="Proxy" minOccurs="0" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="Enabled" type="xs:string" minOccurs="0" />
<xs:element name="Url" type="xs:string" minOccurs="0" />
<xs:element name="Port" type="xs:string" minOccurs="0" />
<xs:element name="Login" type="xs:string" minOccurs="0" />
<xs:element name="Password" type="xs:string" minOccurs="0" />
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="Feeds" minOccurs="0" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="Feed" minOccurs="0" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="Description" type="xs:string"
minOccurs="0" />
<xs:element name="Url" type="xs:string"
minOccurs="0" />
<xs:element name="DateTimeCorrection"
type="xs:string" minOccurs="0" />
<xs:element name="RefreshInterval" type="xs:string"
minOccurs="0" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="NewDataSet" msdata:IsDataSet="true"
msdata:UseCurrentLocale="true">
<xs:complexType>
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:element ref="Settings" />
</xs:choice>
</xs:complexType>
</xs:element>
</xs:schema>
Jul 6 '06 #1
1 1559
Finally found the cause of all this misery.
Visual Studio is to blame. Whenever there is a xsd in the project it
renders its own class for it. When I excluded the xsd from the project
and only included the generated cs, the xml deserialised without errors.

Sjaakie schreef:
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>
<DebugEmail>...</DebugEmail>
<Proxy>
<Enabled>...</Enabled>
<Url>...</Url>
<Port>...</Port>
<Login>...</Login>
<Password>...</Password>
</Proxy>
<Feeds>
<Feed>
<Description>...</Description>
<Url>...</Url>
<DateTimeCorrection>...</DateTimeCorrection>
<RefreshInterval>...</RefreshInterval>
</Feed>
<Feed>
<Description>...</Description>
<Url>...</Url>
<DateTimeCorrection>...</DateTimeCorrection>
<RefreshInterval>...</RefreshInterval>
</Feed>
</Feeds>
</Settings>

But somehow I cannot use the output to deserialize the file. The VS2005
debugger throws the following message:

error CS0030: cannot convert type SettingsFeedsFeed[] to
SettingsFeedsFeed

I use this code to deserialize the file:
FileStream fs = new FileStream(@"Data\Settings.xml", FileMode.Open);
XmlSerializer serializer = new XmlSerializer(typeof(Settings));
settings = (Settings)serializer.Deserialize(fs);
Below are snippets of the generated cs file and the complete xsd.
Can you help me out?

SNIP
Jul 7 '06 #2

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

Similar topics

1
by: Justin Armstrong | last post by:
I'm having difficulties deserializing some objects. Consider the following example of what I'm trying to do: ---------------------------------------------------------- class Person { string...
4
by: Wayne Wengert | last post by:
Using VB.NET I want to read in an XML file that has an array of objects and then step through the resulting array in code. I build a class to define the structure and I am running code to read in...
2
by: Earl Teigrob | last post by:
I am saving and restoring value types such as Int32, DateTime and Boolean in strings. I was wondering if there is a mechanism build into .NET for serializing and deserializing these to string...
1
by: Bob Rock | last post by:
Hello, always having to validate an XML stream against a XSD may add up an important overhead. My XMLs are usually the result of serializing a class instance and often in my applications what I...
5
by: Daniel Gackle | last post by:
I'm getting a strange ArgumentNullException after deserializing a SortedList. Haven't seen this discussed in the newsgroups, but it looks like a bug - unless I missed something obvious? I've...
6
by: Steve Teeples | last post by:
I use serialization to write class data to a file. During my development of this class I need to add properties or fields on occation. After adding a property, when deserializing the data saved...
7
by: Railinc | last post by:
Hi... I'm trying to write a web service client and am running into a problem with getting a response back from the server. I know that a full xml message is being returned (thanks to a tcp/ip...
0
by: Sivajee Akula | last post by:
Hello All, I am trying to consume a .NET Service from Adobe LiveCycle Workflow. The service deals with complex objects. I am getting the following exception at the time of invocation of the...
1
by: =?Utf-8?B?SmVyZW15X0I=?= | last post by:
I am working on an order entry program and have a question related to deserializing nodes with nested elements. The purchase order contains multiple line items which I select using an...
0
by: ullner | last post by:
I have an XML fil that looks like this: <Environment> <AreaOfInterest> <Name>ScenarioMap</Name> <UpperRight> <GDC> <Latitude>-179</Latitude> ...
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
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...

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.