Here's an example that works.
Compile with
vbc.exe /t:exe /debug+ /R:System.dll /R:System.Data.dll
/R:System.XML.dll /out:collect.exe collect.vb
-Dino
====================================
Imports System
Imports System.Xml.Serialization
Public Class clsPerson
Public FirstName As String
Public LastName As String
Public SSN As String
<XmlArrayItem(ElementName := "num", Type:= GetType(String)) , _
XmlArray(ElementName := "PhoneNumbers")> _
Public PhoneNumbers as System.Collections.ArrayList
Public Sub New()
PhoneNumbers = New System.Collections.ArrayList
End Sub
End Class
Public class Test1
Public Function BuildXML()
Dim oPerson As New clsPerson()
oPerson.FirstName = "John"
oPerson.LastName = "Smith"
oPerson.PhoneNumbers.Add("123-456-7890")
oPerson.PhoneNumbers.Add("456-543-4245")
oPerson.PhoneNumbers.Add("777-466-7446")
Dim xmlS1 As New XmlSerializer(GetType(clsPerson))
Dim swri1 As New System.IO.StringWriter()
Dim xwri1 As New System.Xml.XmlTextWriter(swri1)
xwri1.Formatting = System.Xml.Formatting.Indented
xmlS1.Serialize(swri1, oPerson)
''Copy to Clipboard for EZ Access While Troubleshooting
'Clipboard.SetDataObject(swri1.ToString())
'MsgBox(swri1.ToString())
System.Console.WriteLine(swri1.ToString())
swri1.Close()
End Function
Public Shared Sub Main()
Dim pippo as New Test1
pippo.BuildXml()
End Sub
End Class
"Tappy Tibbons" <ta**********@sbcglobal.net> wrote in message
news:O5**************@TK2MSFTNGP09.phx.gbl...
I have been trying everything I can find to add a collection to a class
that will be run through the XML Serializer, and am coming up with nothing THAT
WORKS. Can anyone help point me in the right direction?
I imagine it would go something like this, but I can't put all the pieces
together to actually make it work....
See the code lines with XXXXX below.... What should the XXXXX's be? What
else would be required to do to use XXXXX?
VB.NET SAMPLE CODE:
==========================
Public Class clsPerson
Public FirstName As String
Public LastName As String
Public SSN As String
Public PhoneNumbers as XXXXX
End Class
Public Function BuildXML()
Dim oPerson As New clsPerson()
oPerson.FirstName = "John"
oPerson.LastName = "Smith"
oPerson.PhoneNumbers.AddXXXXX("123-456-7890")
oPerson.PhoneNumbers.AddXXXXX("456-543-4245")
oPerson.PhoneNumbers.AddXXXXX("777-466-7446")
Dim xmlS1 As New XmlSerializer(GetType(clsPerson))
Dim swri1 As New StringWriter()
Dim xwri1 As New XmlTextWriter(swri1)
xwri1.Formatting = Formatting.Indented
xmlS1.Serialize(swri1, oPerson)
'Copy to Clipboard for EZ Access While Troubleshooting
Clipboard.SetDataObject(swri1.ToString())
MsgBox(swri1.ToString())
swri1.Close()
End Function