XML DeSerialization

XML, serving as a versatile and widely adopted general-purpose tag-based language, provides a seamless and efficient means to transfer and store data across diverse applications. XML Serialization, on the other hand, refers to the process of converting a .NET object into an XML file or vice versa. This process enables the representation of complex .NET objects in an XML format, allowing for easy interchange and persistence of data.

During XML serialization, it is important to note that only the public properties and fields of an object are serialized. This means that private or internal members of an object are not included in the serialized XML representation. By selectively serializing public properties and fields, XML serialization offers a controlled and streamlined approach to representing and storing object data in XML format.

DeSerialization

The following C# source code shows how to De-Serialize the DataSet as it is streamed from an XML file back into memory.

Full Source C#
using System; using System.Data; using System.Windows.Forms; using System.Xml.Serialization ; using System.IO; namespace WindowsApplication1 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { DataSet ds = new DataSet(); XmlSerializer xmlSerializer = new XmlSerializer(typeof(DataSet)); FileStream readStream = new FileStream("serialXML.xml", FileMode.Open); ds = (DataSet)xmlSerializer.Deserialize(readStream); readStream.Close(); dataGridView1.DataSource = ds.Tables[0]; } } }

Click here to download serialXML.xml

Conclusion

The XML serialization process plays a critical role in scenarios where data needs to be transmitted or stored in a format that can be readily understood and processed by different systems and platforms. By converting .NET objects to XML files, or vice versa, XML serialization bridges the gap between object-oriented programming and XML-based data representation, facilitating seamless data exchange and interoperability across different applications and environments.