473,946 Members | 10,737 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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>
<ApplicationTit le>...</ApplicationTitl e>
<DebugEmail>... </DebugEmail>
<Proxy>
<Enabled>...</Enabled>
<Url>...</Url>
<Port>...</Port>
<Login>...</Login>
<Password>... </Password>
</Proxy>
<Feeds>
<Feed>
<Description>.. .</Description>
<Url>...</Url>
<DateTimeCorrec tion>...</DateTimeCorrect ion>
<RefreshInterva l>...</RefreshInterval >
</Feed>
<Feed>
<Description>.. .</Description>
<Url>...</Url>
<DateTimeCorrec tion>...</DateTimeCorrect ion>
<RefreshInterva l>...</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 SettingsFeedsFe ed[] to
SettingsFeedsFe ed

I use this code to deserialize the file:
FileStream fs = new FileStream(@"Da ta\Settings.xml ", FileMode.Open);
XmlSerializer serializer = new XmlSerializer(t ypeof(Settings) );
settings = (Settings)seria lizer.Deseriali ze(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.Seri alization.XmlAr rayAttribute(Fo rm=System.Xml.S chema.XmlSchema Form.Unqualifie d)]
[System.Xml.Seri alization.XmlAr rayItemAttribut e("Feed",
typeof(Settings FeedsFeed),
Form=System.Xml .Schema.XmlSche maForm.Unqualif ied, IsNullable=fals e)]
public SettingsFeedsFe ed[][] Feeds {
get {
return this.feedsField ;
}
set {
this.feedsField = value;
}
}
...

}
[System.CodeDom. Compiler.Genera tedCodeAttribut e("xsd", "2.0.50727. 42")]
[System.Serializ ableAttribute()]
[System.Diagnost ics.DebuggerSte pThroughAttribu te()]
[System.Componen tModel.Designer CategoryAttribu te("code")]
[System.Xml.Seri alization.XmlTy peAttribute(Ano nymousType=true )]
public partial class SettingsFeedsFe ed {

private string descriptionFiel d;

private string urlField;

private string dateTimeCorrect ionField;

private string refreshInterval Field;

[System.Xml.Seri alization.XmlEl ementAttribute( Form=System.Xml .Schema.XmlSche maForm.Unqualif ied)]
public string Description {
get {
return this.descriptio nField;
}
set {
this.descriptio nField = 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="u rn:schemas-microsoft-com:xml-msdata">
<xs:element name="Settings" >
<xs:complexType >
<xs:sequence>
<xs:element name="Applicati onTitle" type="xs:string "
minOccurs="0" />
<xs:element name="DebugEmai l" type="xs:string " minOccurs="0" />
<xs:element name="Proxy" minOccurs="0" maxOccurs="unbo unded">
<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="unbo unded">
<xs:complexType >
<xs:sequence>
<xs:element name="Feed" minOccurs="0" maxOccurs="unbo unded">
<xs:complexType >
<xs:sequence>
<xs:element name="Descripti on" type="xs:string "
minOccurs="0" />
<xs:element name="Url" type="xs:string "
minOccurs="0" />
<xs:element name="DateTimeC orrection"
type="xs:string " minOccurs="0" />
<xs:element name="RefreshIn terval" 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="NewDataSe t" msdata:IsDataSe t="true"
msdata:UseCurre ntLocale="true" >
<xs:complexType >
<xs:choice minOccurs="0" maxOccurs="unbo unded">
<xs:element ref="Settings" />
</xs:choice>
</xs:complexType>
</xs:element>
</xs:schema>
Jul 6 '06 #1
1 1589
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>
<ApplicationTit le>...</ApplicationTitl e>
<DebugEmail>... </DebugEmail>
<Proxy>
<Enabled>...</Enabled>
<Url>...</Url>
<Port>...</Port>
<Login>...</Login>
<Password>... </Password>
</Proxy>
<Feeds>
<Feed>
<Description>.. .</Description>
<Url>...</Url>
<DateTimeCorrec tion>...</DateTimeCorrect ion>
<RefreshInterva l>...</RefreshInterval >
</Feed>
<Feed>
<Description>.. .</Description>
<Url>...</Url>
<DateTimeCorrec tion>...</DateTimeCorrect ion>
<RefreshInterva l>...</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 SettingsFeedsFe ed[] to
SettingsFeedsFe ed

I use this code to deserialize the file:
FileStream fs = new FileStream(@"Da ta\Settings.xml ", FileMode.Open);
XmlSerializer serializer = new XmlSerializer(t ypeof(Settings) );
settings = (Settings)seria lizer.Deseriali ze(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
2066
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 name; } class Info {
4
7520
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 the data but I can't figure out where the data is in the resulting array. Most of the relevant code is below. When I run the code to desrialize I get no errors but if I try to look at some of the data via the command window I get errors such as...
2
3105
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 format. I can, of course, serialize a class to a file, either binary or XML, but this is not what I am looking for. Currently I am using ToString() or Convert.xxx to do this, but thought that if there was a true serializer, deserializer, that would be...
1
1455
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 end up doing is just deserializing it back into a new instance of the same class. Considering what I just said what I often end up doing is not validating my XML to be deserialized and just try deserializing it into an instance of the class and...
5
3170
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 distilled the problem into the following code. Can anybody reproduce/explain the problem? Thanks, Daniel
6
1598
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 to disk I get an exception error indicating that the class data members no longer match. To avoid the exception errors, how can I retrieve data from the disk and populate the existing fields found within the file and set defaults for the new...
7
5959
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 sniffer) but in VS.NET all I get is a null reference. The server is a java program running on websphere. The provider of the web service has gotten a websphere client and an apache axis client to work correctly, so I don't think it's a problem...
0
7829
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 service, and due to which my workflow gets stalled. When I searched the net, I found many posts reporting this error, but none with a solution. There is no code involved in the invocation, everything is handled by Adobe tool itself. I just specify the...
1
11834
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 XmlNodeList. I am trying to deserialize the nodes using a foreach as follows: foreach(XmlNode lineItem in LineItemsNodeList) An abbreviated example of the nested lineItem node looks like this:
0
993
by: ullner | last post by:
I have an XML fil that looks like this: <Environment> <AreaOfInterest> <Name>ScenarioMap</Name> <UpperRight> <GDC> <Latitude>-179</Latitude> <Longitude>-179</Longitude>
0
10151
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
11556
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...
1
11331
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10683
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
8244
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
7410
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
6106
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
4932
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
3532
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.