xml add
Objekt als XML speichern:
Imports System
Imports System.IO
Imports System.Runtime.Serialization
Imports System.Runtime.Serialization.Formatters.Soap
Module Attribute
Sub main()
Dim tn1 As New Teilnehmer()
tn1.name = "Anton"
tn1.alter = 34
Dim stream As Stream = _
File.Open("tn.xml", FileMode.Create)
Dim formatter As IFormatter = New SoapFormatter()
formatter.Serialize(stream, tn1)
stream.Close()
Dim tn2 As New Teilnehmer()
stream = File.Open("tn.xml", FileMode.Open)
tn2 = CType(formatter.Deserialize(stream), Teilnehmer)
stream.Close()
Console.WriteLine(tn2)
Console.ReadLine()
End Sub
End Module
Public Class Teilnehmer
Public name As String
Public alter As Integer
Public Overrides Function toString() As String
Return name & " ist " & alter & "Jahre alt"
End Function
End Class
|