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.

You might also like...

Comments

About the author

Anthony Hart United States

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 mus...

Interested in writing for us? Find out more.

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“XML is like violence - if it's not working for you, you're not using enough of it.”