Wrox Programmer Forums
|
Pro VB.NET 2002/2003 For advanced Visual Basic coders working .NET version 2002/2003. Beginning-level questions will be redirected to other forums, including Beginning VB.NET.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Pro VB.NET 2002/2003 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old August 17th, 2004, 02:02 AM
Registered User
 
Join Date: Aug 2004
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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>







Similar Threads
Thread Thread Starter Forum Replies Last Post
VB.net, adding XML data to an existing XML file saikoboarder XML 11 April 17th, 2008 04:19 PM
DTS Package, XML task. Read XML file and store it Victoria SQL Server DTS 0 July 24th, 2006 02:43 PM
Problem to create an xml file from two xml files saurabh_inblore XSLT 1 April 12th, 2006 02:58 AM
Convert xml to an arraylist manu1076 XML 0 May 19th, 2004 07:27 AM
Merge XML files into a xml file using xslt lxu XML 4 November 6th, 2003 06:01 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.