IT Community - Software Programming, Web Development and Technical Support

How to serialize an xml file in C#? Is any easy way for serialization?

This is a discussion on How to serialize an xml file in C#? Is any easy way for serialization? within the C# Programming forums, part of the Software Development category; How to serialize an xml file in C#? Is any easy way for serialization? Hi all, I need to serialize ...


Go Back   IT Community - Software Programming, Web Development and Technical Support > Software Development > C# Programming

Register FAQ Members List Calendar Mark Forums Read
  #1 (permalink)  
Old 07-17-2007, 03:52 AM
mobilegeek mobilegeek is offline
D-Web Analyst
 
Join Date: Jun 2007
Posts: 205
mobilegeek is on a distinguished road
Default How to serialize an xml file in C#? Is any easy way for serialization?

How to serialize an xml file in C#? Is any easy way for serialization?
Hi all, I need to serialize an xml file in c#. Can anybody help me?

Last edited by mobilegeek : 07-30-2007 at 05:25 AM.
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 07-30-2007, 05:26 AM
kingmaker kingmaker is offline
D-Web Genius
 
Join Date: Jun 2007
Posts: 882
kingmaker is on a distinguished road
Send a message via Yahoo to kingmaker
Default Re: How to serialize an xml file in C#? Is any easy way for serialization?

Hi ,

We can serialize an xml file using the XMLSerializer class in .Net. First we need to create a property class for that xml file. Here is the example for serialization in C#.


XmlSerializer serializer = new XmlSerializer(typeof(myClass));

// myClass is the property class for the xml.

string path = Environment.CurrentDirectory + "test.xml";
TextWriter writer = new StreamWriter(path);
serializer.Serialize(writer, myClassObj);
writer.Close();

Hope informative
__________________
The KINGMAKER
Makes Every Thing Possible

Stuffs (My Blog)
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 08-17-2007, 07:58 AM
krishnakumar krishnakumar is offline
D-Web Analyst
 
Join Date: May 2007
Posts: 206
krishnakumar is on a distinguished road
Wink Re: How to serialize an xml file in C#? Is any easy way for serialization?

Hi,
I used the above code for serialise the xml file... Its worked perfectly...How can we deserialise it.... Can u give sample code for it...
__________________
Krishnakumar.S
Beware of Everything -that is un true; stick to the Truth shall succeed slowly but steadily
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 08-21-2007, 01:24 AM
S.Vinothkumar S.Vinothkumar is offline
D-Web Genius
 
Join Date: May 2007
Posts: 1,061
S.Vinothkumar is on a distinguished road
Wink Re: How to serialize an xml file in C#? Is any easy way for serialization?

Hi,

The reverse process of Serialization is De Serialization.

Simply do as following,

FileStream fs = File.OpenRead(Environment.CurrentDirectory + "\\test.xml");
myClassObj=(myClass)serializer.Deserialize(fs);


That's it...
__________________
S.VinothkumaR
Behind me is infinite power,
Before me is Endless Possibility,
Around me is Boundless Opportunity,
Why should I fear!
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Easy Property Class Generator for DOTNET Developers Anandavinayagam ASP and ASP.NET Programming 4 01-16-2008 03:54 AM
Easy way to improve Google ranking?? ammulu Google 0 12-26-2007 06:57 PM
Creating easy site wide links through css bermuda HTML, CSS and Javascript Coding Techniques 0 10-12-2007 05:18 AM
Is it getting easy? googoo General Web hosting Discussions 5 03-28-2007 08:31 AM
What SPAM means in easy word? montyauto Advertising Sales and Affiliate Programs 5 03-14-2007 11:35 PM


All times are GMT -7. The time now is 05:13 PM.


Copyright ©2004 - 2007, DiscussWeb. All Rights Reserved.

SEO by vBSEO 3.0.0