XML Serialization : XmlSerializer « XML « VB.Net Tutorial

Home
VB.Net Tutorial
1.Language Basics
2.Data Type
3.Operator
4.Statements
5.Date Time
6.Class Module
7.Development
8.Collections
9.Generics
10.Attributes
11.Event
12.LINQ
13.Stream File
14.GUI
15.GUI Applications
16.Windows Presentation Foundation
17.2D Graphics
18.I18N Internationlization
19.Reflection
20.Regular Expressions
21.Security
22.Socket Network
23.Thread
24.Windows
25.XML
26.Database ADO.net
27.Design Patterns
VB.Net
VB.Net by API
VB.Net Tutorial » XML » XmlSerializer 
25.7.3.XML Serialization
Imports System.IO
Imports System.Xml.Serialization
Public Class Point
  Public As Integer
  Public As Integer

  Public Overrides Function ToString() As String
    Return "(" & X & "," & Y & ")"
  End Function 
End Class

Module Test
  Sub Main()
    Dim P1 As New Point()
    P1.X = 6
    P1.Y = 4
    SaveToFile(P1)

    Dim P2 As Point = RetrieveFromFile()
    Console.WriteLine(P2.ToString())
  End Sub

  Sub SaveToFile(P as Point)
    Dim Serializer As New XmlSerializer(GetType(Point))
    Dim Writer As StreamWriter = New StreamWriter("point.xml"
    Serializer.Serialize(Writer, P
    Writer.Close()
  End Sub

  Function RetrieveFromFile() As Point
    Dim ReturnObject As Point
    Dim Serializer As New XmlSerializer(GetType(Point)) 
    Dim FS As FileStream = New FileStream("point.xml", FileMode.Open

    ReturnObject = CType(Serializer.Deserialize(FS), Point
    FS.Close()
    Return ReturnObject
  End Function
End Module
(6,4)
25.7.XmlSerializer
25.7.1.Serialize Class to xml file
25.7.2.DeSerialize from xml file
25.7.3.XML Serialization
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.