|
-
Jun 4th, 2004, 04:41 PM
#1
Thread Starter
New Member
Deserializing xml-file with array of objects
I have some problems deserializing a xml-file. Here is some info:
---
' Here is my class, simplified:
<Serializable()> Public Class Job
' main settings
public strName As String
public strDescription As String
public strCmdLine As String
End Class
---
Here is my array defined in a module (the array is used for saving because the main info is in a hashtable which can't be serialized):
Public JobArray() As Job
---
Here is the hashtable defined:
Public Jobs As New Hashtable
---
First I have a function to save to an xml file (this function works and saves the whole array):
ReDim JobArray(Jobs.Count - 1)
Dim objStreamWriter As New StreamWriter("job.xml")
Dim x As New XmlSerializer(JobArray.GetType)
Dim i As Integer
' I loop through a datagrid to get my sorted order and place it in the arrray
For i = 0 To lVirtualTable.Rows.Count - 1
Dim j As Job = DirectCast(Jobs(lVirtualTable.Rows(i).Item(0)), Job)
JobArray(i) = j
Next
Try
x.Serialize(objStreamWriter, JobArray)
Catch e As Exception
MsgBox(e.Message.ToString)
End Try
objStreamWriter.Close()
End Sub
---
Now I want to deserialize the xml fil but I am doing something wrong, I want to do something like this below but this doesnt work. I get several errors both at runtime and in design:
Public Sub LoadJobs()
Dim objStreamReader As New StreamReader("job.xml")
Dim x As New XmlSerializer(JobArray.GetType)
' this one below is totally wrong, first I don't
JobArray() = CType(x.Deserialize(objStreamReader), Job)
Dim i As Integer
x.Deserialize(objStreamReader)
For i = 0 To UBound(JobArray)
Call AddToTable(JobArray(i))
Call Jobs.Add(JobArray(i).Name, JobArray(i))
Next
objStreamReader.Close()
End Sub
---
Thankful for your help!
--- neteject.com - Internet Solutions ---
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|