Problems with deserializing XML

S

Sjaakie

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=System.Xml.Schema.XmlSchemaForm.Unqualified)]
[System.Xml.Serialization.XmlArrayItemAttribute("Feed",
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("xsd", "2.0.50727.42")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType=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>
 
S

Sjaakie

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,904
Latest member
HealthyVisionsCBDPrice

Latest Threads

Top