Serialize Class to XML Document : XML Serialize « XML « VB.Net






Serialize Class to XML Document

  
Imports System
Imports System.Xml.Serialization
Imports System.IO

Public Class MainClass

   Shared Sub Main()
        Dim emp As New Employee("Joe", "Yin")
        Dim string_writer As New StringWriter()
        Dim serializer As New XmlSerializer(GetType(Employee))
        serializer.Serialize(string_writer, emp)
        Console.WriteLine(string_writer.ToString)
   End Sub 

End Class

    <Serializable()> _
    Public Class Employee
        Public FirstName As String
        Public LastName As String
        Public Sub New()
        End Sub
        Public Sub New(ByVal first_name As String, ByVal last_name As String)
            FirstName = first_name
            LastName = last_name
        End Sub
    End Class

 
           
         
    
  








Related examples in the same category

1.XmlSerializer DemoXmlSerializer Demo
2.Serializes an object using an XmlWriter.
3.Saves the XML document to the specified file.
4.SaveOptions.None