How to de-serialize from an XML file to .Net Object

XML is a general purpose tag based language and very easy to transfer and store data across applications. XML Serialization is the process of serializing a .Net Object to the form of XML file or from an XML to .Net Object.

During XML serialization, only the public properties and fields of an object are serialized. The following source code shows how to de-serialize the DataSet as it is streamed from an XML file back into memory.

Imports System.Xml.Serialization
Public Class Form1
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim ds As New DataSet
        Dim xmlSerializer As XmlSerializer = New XmlSerializer(ds.GetType)
        Dim readStream As FileStream = New FileStream("serialXML.xml", FileMode.Open)
        ds = CType(xmlSerializer.Deserialize(readStream), DataSet)
        DataGridView1.DataSource = ds.Tables(0)
    End Sub
End Class

Click here to download serialXML.xml (C) 2021    Founded by raps mk
All Rights Reserved. All other trademarks are property of their respective owners.
SiteMap  | Terms  | About