VB.NET || How To Serialize & Deserialize XML Using VB.NET

Print Friendly, PDF & Email

The following is a module with functions which demonstrates how to serialize and deserialize XML using VB.NET.

The following generic functions use System.Xml.Serialization to serialize and deserialize an object.


1. Serialize – Integer Array

The example below demonstrates the use of ‘Utils.Xml.Serialize‘ to serialize an integer array to xml.

The optional function parameter allows you to specify the System.Xml.Serialization.XmlRootAttribute.


2. Serialize – String List

The example below demonstrates the use of ‘Utils.Xml.Serialize‘ to serialize a list of strings to xml.

The optional function parameter allows you to specify the System.Xml.Serialization.XmlRootAttribute.


3. Serialize – Custom Object List

The example below demonstrates the use of ‘Utils.Xml.Serialize‘ to serialize a list of custom objects to xml.

The optional function parameter allows you to specify the System.Xml.Serialization.XmlRootAttribute.


4. Deserialize – Integer Array

The example below demonstrates the use of ‘Utils.Xml.Deserialize‘ to deserialize xml to an integer array.

The optional function parameter allows you to specify the System.Xml.Serialization.XmlRootAttribute.


5. Deserialize – String List

The example below demonstrates the use of ‘Utils.Xml.Deserialize‘ to deserialize xml to a list of strings.

The optional function parameter allows you to specify the System.Xml.Serialization.XmlRootAttribute.


6. Deserialize – Custom Object List

The example below demonstrates the use of ‘Utils.Xml.Deserialize‘ to deserialize xml to a list of objects.

The optional function parameter allows you to specify the System.Xml.Serialization.XmlRootAttribute.


7. Utils Namespace

The following is the Utils Namespace. Include this in your project to start using!


8. More Examples

Below are more examples demonstrating the use of the ‘Utils‘ Namespace. Don’t forget to include the module when running the examples!

QUICK NOTES:
The highlighted lines are sections of interest to look out for.

The code is heavily commented, so no further insight is necessary. If you have any questions, feel free to leave a comment below.

Leave a Reply