Arraylist in XML file
Do you have any idea how to use this code to serializing and deserializing as an arraylist..
which means i want to create one person class as xml file as the main Element...
then each customer with name and age as sub nodes...
When i run the textbox the second times.....
it create two array of customer inside the person xml files....
Code:
Imports System.XML
Imports System.XML.Serialization
Imports System.IO
Public Class Person
Private m_sName As String
Private m_iAge As Integer
Public Property Name() As String
Get
Return m_sName
End Get
Set(ByVal sNewName As String)
m_sName = sNewName
End Set
End Property
Public Property Age() As Integer
Get
Return m_iAge
End Get
Set(ByVal iNewAge As Integer)
m_iAge = iNewAge
End Set
End Property
End class
-----------------------------------------------------------------------
Imports System.Xml.Serialization
Imports System.IO
Public Class Form1
Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click
'SERIALIZE TO A FILE
Dim oXS As XmlSerializer = New XmlSerializer(GetType(Person))
Dim oLucky As New Person
Dim oStmW As StreamWriter
'Set properties
oLucky.Name = txtName.Text
oLucky.Age = txtAge.Text
'Serialize object to XML and write it to XML file
oStmW = New StreamWriter("lucky.xml")
oXS.Serialize(oStmW, oLucky)
oStmW.Close()
End Sub
End Class
--------------------------------------------------------------------
This code can only create one array....it will overwrite the content if i enter again..
Examples of Arraylist inside xml:
<Person>
<Name> A </Name>
<Age>34</Age>
<Name> B </Name>
<Age>56</Age>
</Person>
|