View Single Post
  #2 (permalink)  
Old 08-01-2007, 06:27 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
Thumbs up Re: Serialization and Deserialization

A more elegant solution is to use the serialization and deserialization features of XML. A serialization is a series of data values, usually text, which represents an object. It contains the object's public and private variables, and any other information needed to completely describe the object. For example, suppose a Student object contains LastName and FirstName variables, and an array of test scores. The XML serialization of a Student object might look like this:

<Student>
<LastName>Stephens</LastName>
<FirstName>Rod</FirstName>
<TestScore TestNumber="1" Score="80" />
<TestScore TestNumber="2" Score="92" />
<TestScore TestNumber="3" Score="87" />
<TestScore TestNumber="4" Score="94" />
</Student>

Building a serialization for a class is simple enough following roughly the same steps you would take to save the object in a database, as described in the previous section. The class just concatenates the object's variable values into a string. Later, it could parse the serialization string to restore the object. To make an XML serialization, the class includes the proper tags.

This method works, but has some of the same drawbacks as the previous method. In particular, if you modify the class, you need to modify the code that reads and writes the serialization.


xml_serializer As New XmlSerializer(GetType(Person)


xml_serializer.Serialize(string_writer, customer)



Here's what an actual serialization produced by the XmlSerializer might look like:

<?xml version="1.0" encoding="utf-16"?>
<Person xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<LastName>Stephens</LastName>
<FirstName>Rod</FirstName>
<EmailAddress>RodStephens@vb-helper.com</EmailAddress>
</Person>


  1. Class SOAP Deserialization
  2. Object Serialization
__________________
The KINGMAKER
Makes Every Thing Possible

Stuffs (My Blog)
Reply With Quote