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

XML Serialization

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>
Jul 4 '06 #1
4 2639
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>
Jul 4 '06 #2

Sjaakie <ke**@secret.itwrote:
I've read some articles on serialization, but I don't see how to serialize
the xml-structure below [...]
Just curious: what's the point of serializing XML?
Isn't XML already serial?
Why would you want to drown a dead fish?
Jul 4 '06 #3
Ole Nielsby schreef:
Sjaakie <ke**@secret.itwrote:
>I've read some articles on serialization, but I don't see how to serialize
the xml-structure below [...]

Just curious: what's the point of serializing XML?
Isn't XML already serial?
Why would you want to drown a dead fish?
You're right, I meant DEserializing
Jul 5 '06 #4
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>
Jul 5 '06 #5

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

Similar topics

37
by: Ben | last post by:
Hi, there. Recently I was working on a problem where we want to save generic closures in a data structure (a vector). The closure should work for any data type and any method with pre-defined...
1
by: andrewcw | last post by:
There is an error in XML document (1, 2). I used XML spy to create the XML and XSD. When I asked to have the XML validated it said it was OK. I used the .net SDK to generate the class. I have...
3
by: Aaron Clamage | last post by:
Hi, I'm not sure that if this is the right forum, but any help would be greatly appreciated. I am porting some java serialization code to c# and I can't figure out the correct way to do it. ...
6
by: Uttam | last post by:
Hello, We are at a very crucial decision making stage to select between .Net and Java. Our requirement is to download a class at runtime on the client computer and execute it using remoting or...
3
by: Alexander | last post by:
When i store rule on PC with .NET.SP1 i cant restore them from PC without SP1. An i get this Error: System.Runtime.Serialization.SerializationException: Possible Version mismatch. Type...
4
by: mijalko | last post by:
Hi, I have inherited my class from System.Drawing.Printing.PrintDocument and I wish to serialize this object using XmlSerializer. And I get exception "There was an error reflecting type ...". If I...
5
by: Nikola Skoric | last post by:
I ran in Mono a program developed on .NET Framework 2.0 and it ran OK until I tried to desirialize a object. There the program died abruptly dumping this: System.ArgumentOutOfRangeException:...
0
by: bharathreddy | last post by:
Before going to that i want to say few thing on serialization : Serialization is the process of converting an object into a form that can be readily transported. For example, you can serialize an...
1
by: kikisan | last post by:
I am developing a windows service which utilizes the following classes: interface IPersistable; abstract class PersistableObject : IPersistable;
2
by: mkvenkit.vc | last post by:
Hello, I hope this is the right place to post a question on Boost. If not, please let me know where I can post this message and I will do so. I am having a strange problem with std::string as...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

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.