Tantr,
I used the xsd util as described. 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>
Tantr Mantr schreef:
use the xsd utility to generate a schema for this xml file. Use this schema
with the xsd utility to generate the class file.
1) xsd myFile.xml
2)xsd myFile.xsd /c
Use the generated Class in your project to Serialize the xml.
Hope this helps.
Cheers!
"Sjaakie" wrote:
>Hi,
I've read some articles on serialization, but I don't see how to
serialize the xml-structure below (if it is possible at all). Could you
point me in the right direction?
TIA
<?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>