B
Brad
I would like to serialize an arraylist of objects to xml so I can store the
xml in a database column. How would I code the serializing and
deserializing? Below is a (overly) simple, incomplete example of what I'd
want to accomplish.
Thanks
Brad
Example
=================================
' This object will be used in an arraylist
Public Class MyObject
Private _name as string
Public Property Name as string
Get
Return _name as string
End Get
Set (ByVal Value)
_name = Value
End Set
End Property
End Class
=================================
' This object will serialize xml for
Public Class BusLayer
Public Sub Update
Dim myList as new ArrayList
Dim mo1 as new MyObject
mo1.Name = "Jack"
myList.Add(mo1)
Dim mo2 as new MyObject
mo2.Name = "Jill"
myList.Add(mo2)
' Serializing code. What I've figure out so far but does not
work.
Dim mySerializer As New
System.Xml.Serialization.XmlSerializer(GetType(ArrayList))
Dim strWriter As New StringWriter
Dim writer As New XmlTextWriter(strWriter)
writer.Formatting = Formatting.Indented
mySerializer.Serialize(writer, attributeValues)
Dim result as string = strWriter.ToString
' String xml can now be written to database in stored procedure
parameter...easy to do
End Sub
Public Sub Read
Dim dbString as string
' Deserializing code here assume dbString already read from database
' and needs to be deserialized. How????
End Sub
End Class
xml in a database column. How would I code the serializing and
deserializing? Below is a (overly) simple, incomplete example of what I'd
want to accomplish.
Thanks
Brad
Example
=================================
' This object will be used in an arraylist
Public Class MyObject
Private _name as string
Public Property Name as string
Get
Return _name as string
End Get
Set (ByVal Value)
_name = Value
End Set
End Property
End Class
=================================
' This object will serialize xml for
Public Class BusLayer
Public Sub Update
Dim myList as new ArrayList
Dim mo1 as new MyObject
mo1.Name = "Jack"
myList.Add(mo1)
Dim mo2 as new MyObject
mo2.Name = "Jill"
myList.Add(mo2)
' Serializing code. What I've figure out so far but does not
work.
Dim mySerializer As New
System.Xml.Serialization.XmlSerializer(GetType(ArrayList))
Dim strWriter As New StringWriter
Dim writer As New XmlTextWriter(strWriter)
writer.Formatting = Formatting.Indented
mySerializer.Serialize(writer, attributeValues)
Dim result as string = strWriter.ToString
' String xml can now be written to database in stored procedure
parameter...easy to do
End Sub
Public Sub Read
Dim dbString as string
' Deserializing code here assume dbString already read from database
' and needs to be deserialized. How????
End Sub
End Class