jdross jdross - 2 years ago 112
Vb.net Question

How to serialize an object into XML

How can I serialize a .net object into XML and then de-serialize it back?

Answer Source

In VB.Net you would first add some attributes to your class (if needed)

Public Class Class1

    Public Property Value As String

    Public Property Name As String

End Class

And then serialize it using

Dim p As New Class1()
p.Name = "test"
Dim sw1 = New StringWriter()
Dim xs1 As New XmlSerializer(GetType(Class1))
xs1.Serialize(New XmlTextWriter(sw1), p)
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download