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 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>
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>
<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>