views:

181

answers:

7

Hello, Where Can I find good tutorial about XMl serialization to the object? Thanks.

A: 

MSDN has a decent article about it: http://msdn.microsoft.com/en-us/library/ms733901.aspx

And this one's a bit more straightforward: http://www.dotnetjohn.com/articles.aspx?articleid=173

deltreme
A: 

Here's a good start microsoft

Also look into Xml Schema and generating classes automatically with xsd.exe the sooner you get used to this the better, it can save you a lot of effort working with XML. Also looking at the generated c# files gives you some clues on how to use attributes to manipulate the way classes are serilized by the XmlSerializer

Dog Ears
+2  A: 

There's a basic tutorial on Microsoft's support pages and a slightly more lengthy one on Devhood.

SwitchOnTheCode has a fairly extensive one too.

ChrisF
Thanks a lot for your answer.
jitm
A: 

Its really pretty simple, there are only three main steps.

  1. You need to mark your classes with the [Serializable] attribute.
  2. Write Serialization code
  3. Write Deserialization code

Serialization:

var x = new XmlSerializer(typeof(YourClass));
var fs = new FileStream(@"C:\YourFile.xml"), FileMode.OpenOrCreate);
x.Serialize(fs, yourInstance);
fs.Close();

Deserialization:

var x = new XmlSerializer(typeof(YourClass));
var fs = new FileStream(@"C:\YourFile.xml"), FileMode.Open);
var fromFile = x.Deserialize(fs) as YourClass;
fs.Close();
Nate Bross
A: 

You can easily find many tutorials about serialization data using .Net on the Web. However, let me remind some points:

  1. Types of serialization:

    a. XML Serialization : Please have a look at http://www.switchonthecode.com/tutorials/csharp-tutorial-xml-serialization

    b. Binary Serialization: Please refer to http://www.switchonthecode.com/tutorials/csharp-tutorial-serialize-objects-to-a-file

  2. Also please be aware of the security aspects when you work (reading and writing data) with files. There is a good tutorial here http://msdn.microsoft.com/en-us/library/system.security.permissions.fileiopermission.aspx

DrakeVN
A: 

We use Serialization to write the data in Binary Format and IN XML format. for binary format we use BibnaryFormatSerialization and for XML format we use SoapFormatSerialization.

GauravDeshmukh