473,795 Members | 2,919 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

Sjaakie <ke**@secret.it wrote:
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.it wrote:
>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 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>
Jul 5 '06 #5

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

Similar topics

37
5023
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 signature. When developing this lib, I figured that the pointer-to-member-function, although seemingly an attractive solution, does not work well for us.
1
4365
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 done this before but this time I have no idea why I am getting the error. Any ideas ?? THANKS ! <qcsttatus> <manual sourcerootfolder="" manualname="">
3
3178
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. It seems that either I can use default serialization or implement ISerializable. Is there any way to do both (e.g. extend the default serialization). In other words, I want to be able to implement my custom serialization code but call the...
6
2718
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 rmi. Just to keep my question short I am posting trimmed version of my code. //file: Serializable.cs
3
2460
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 System.Collections.Comparer has 1 members, number of members deserialized is 0. at System.Runtime.Serialization.Formatters.Binary.ReadObjectInfo.GetMemberTypes(String
4
11417
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 look at innerException it says: "Cannot serialize member 'System.ComponentModel.Component.Site' of type 'System.ComponentModel.ISite'. OK it is problem to serialize all data so I'll implement my Serialization. I implemented ISerializable...
5
6118
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: Value -8590321990885400808 is outside the valid range . Parameter name: ticks at System.DateTime..ctor (Int64 ticks) at System.Runtime.Serialization.Formatters.Binary.ObjectReader.ReadPrimitiv
0
6616
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 object and transport it over the Internet using HTTP between a client and a server. On the other end, deserialization reconstructs the object from the stream. XML serialization serializes only the public fields and property values of an object...
1
11109
by: kikisan | last post by:
I am developing a windows service which utilizes the following classes: interface IPersistable; abstract class PersistableObject : IPersistable;
2
5568
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 I am trying to read from a binary archive using Boost serialization. I am new to this, and it is possible that I have not understood the usage. In the code below, the string "faultblock" seems to be causing the problem. The code crashes in the ia...
0
9673
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
9522
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10216
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10002
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
7543
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
5437
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...
0
5565
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4113
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
2
3728
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.