Library tutorials & articles

XML Serialization in .NET

Object Serialization

The technique to which I refer is called "Object Serialization". Object Serialization is a process through which an object's state is transformed into some serial data format, such as XML or a binary format, in order to be stored for some later use. In other words, the object is "dehydrated" and put away until we need to use it again. Let's look at an example to clarify this idea a little further. Suppose we have an object defined and instantiated as shown below:

Public Class Person
private m_sName as string
private m_iAge as integer

public property Name() as string
    get
    return m_sName
    end get
    set(byval sNewName as string)
    m_sName = sNewName
    end set
end property
   
public property Age() as integer
    get
    return m_iAge
    end get
    set(byval iNewAge as integer)
    m_iAge = iNewAge
    end set
end property
End Class
dim oPerson as New Person()
oPerson.Name = "Powdered Toast Man"
oPerson.Age = "38"

Let's say that for some reason, we wanted to save a copy of this object just as it is at this very moment. We could serialize it as an XML document that would look something like this:

<Person>
   <Name>Powdered Toast Man</Name>
   <Age>38</Age>
</Person>

Then, at some later time when we needed to use the object again, we could just deserialize ("rehydrate") it and have our object restored to us just as it was at the moment we serialized it.

Comments

  1. 09 Aug 2007 at 15:58

    Fantastic Article!!

    Thank you so much for writing that article.  That was the first clearly stated explanation on serialization that I have come across and it helped me tremendously!

    Kudos to you my friend!

    Jason Z

  2. 28 Jul 2006 at 11:52

    I have two text boxes in my .aspx form. At the click of a button I need to generate an xml with the following schema.

    <?xml version="1.0" encoding="utf-16"?>
    <ns0:Root xmlns:ns0="http://Demo123.Schm_In">
      <No_1>      Contents of textBox 1       </No_1>
      <No_2>      Contents of textBox 2       </No_2>
    </ns0:Root>



    Now i need to post this through hppt.

    Pls give me the code in C#

  3. 14 Jan 2005 at 08:33
    What does this have to do with raisins? I see no raisins.
  4. 14 Jul 2003 at 11:28

    A good article for XML in .NET. This technology will truely standardize things, its a must for developers to learn and understand this.

  5. 01 Jan 1999 at 00:00

    This thread is for discussions of XML Serialization in .NET.

Leave a comment

Sign in or Join us (it's free).

Anthony Hart Anthony Hart has been working in IT since 1995. Currently, he is managing Oneirasoft, LLC, a consulting and software business. In his free time (if there is such a thing) he enjoys composing music ...

Related discussion

Related podcasts

  • Episode 10: LINQ

    K Scott leads us in a discussion of LINQ, including: What is it How introducing LINQ to .NET changed the framework LINQ Providers LINQ to XML LINQ to SQL - how it's different from EF, tips and tricks, when to use it Links: LINQpad 3rd Party LIN...

Events coming up

  • Dec 9

    GL.net Group Meeting - December 2009

    Gloucester, United Kingdom

    The beginning of this year holiday season will belong to mocks. Ronnie and Stephen will take us for a tour around exciting world of unit testing.

We'd love to hear what you think! Submit ideas or give us feedback