S
Siegfried Heintze
Below is a program I'm translating from C# to VB. The C# version works. I
don't understand how to specify the type on line 55. XmlSerializer wants a
type and I tried to follow the example at
http://msdn2.microsoft.com/en-us/library/system.xml.serialization.xmlserializer.aspx
but it is still not working. I' having a similar problem on line 34 where
the XmlAttributeAttribute can take a type argument.
Thanks,
Siegfried
' Begin commands to execute this file using MS.NET with bash
' vbc /out:Module1.exe /d:noprompt /debug Module1.vb /define:noprompt
' ./Module1 hello there <<EOF
' <?xml version="1.0" encoding="IBM437"?> '
5
' <Persons xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
' <persons>
' <Person>
' <first>Siegfried</first>
' <last>Heintze</last> '
10
' </Person>
' </persons>
' </Persons>
' EOF
' rm Module1.exe '
15
' rm Module1.pdb
' End commands to execute this file using MS.NET with bash
Imports System
Imports System.IO '
20
Imports System.Xml
Imports System.Xml.Serialization
Imports System.Reflection
Imports System.Runtime.InteropServices
Imports System.Collections.Generic '
25
Module Module1
<Serializable()> Public Class Person
Public Sub New()
first = "" : last = ""
End Sub '
30
Public Sub New(ByVal f As String, ByVal l As String)
first = f : last = l
End Sub
<XmlAttributeAttribute("first")> Public first As String
Public last As String '
35
End Class
Public Class Persons
Public Sub New()
persons = Nothing
End Sub '
40
Public Sub New(ByVal ps() As Person)
persons = ps
End Sub
<XmlArrayItem("Person")> Public persons As Person()
End Class '
45
Declare Function _kbhit Lib "msvcrt.dll" () As Integer
Declare Function _getch Lib "msvcrt.dll" () As Integer
Dim outp As System.IO.TextWriter = System.Console.Out
Dim inp As System.IO.TextReader = System.Console.In
Sub Main(ByVal args() As String) '
50
Try
outp.WriteLine("starting Module1.vb")
Dim persons As Persons = New Persons(New Person() { _
New Person("siegfried", "heintze")})
Dim sr As XmlSerializer = New XmlSerializer(GetType([Persons]))'
55
'Dim persons As Persons = CType(sr.Deserialize(inp), Persons)
Dim person As Person
For Each person In persons.persons
person.last = "*" + person.last + "*"
Next '
60
sr.Serialize(outp, persons)
Finally
#If noprompt Then
outp.WriteLine("All done")
#Else '
65
outp.WriteLine("hit any key: ")
_getch()
#End If
End Try
End Sub '
70
End Module
don't understand how to specify the type on line 55. XmlSerializer wants a
type and I tried to follow the example at
http://msdn2.microsoft.com/en-us/library/system.xml.serialization.xmlserializer.aspx
but it is still not working. I' having a similar problem on line 34 where
the XmlAttributeAttribute can take a type argument.
Thanks,
Siegfried
' Begin commands to execute this file using MS.NET with bash
' vbc /out:Module1.exe /d:noprompt /debug Module1.vb /define:noprompt
' ./Module1 hello there <<EOF
' <?xml version="1.0" encoding="IBM437"?> '
5
' <Persons xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
' <persons>
' <Person>
' <first>Siegfried</first>
' <last>Heintze</last> '
10
' </Person>
' </persons>
' </Persons>
' EOF
' rm Module1.exe '
15
' rm Module1.pdb
' End commands to execute this file using MS.NET with bash
Imports System
Imports System.IO '
20
Imports System.Xml
Imports System.Xml.Serialization
Imports System.Reflection
Imports System.Runtime.InteropServices
Imports System.Collections.Generic '
25
Module Module1
<Serializable()> Public Class Person
Public Sub New()
first = "" : last = ""
End Sub '
30
Public Sub New(ByVal f As String, ByVal l As String)
first = f : last = l
End Sub
<XmlAttributeAttribute("first")> Public first As String
Public last As String '
35
End Class
Public Class Persons
Public Sub New()
persons = Nothing
End Sub '
40
Public Sub New(ByVal ps() As Person)
persons = ps
End Sub
<XmlArrayItem("Person")> Public persons As Person()
End Class '
45
Declare Function _kbhit Lib "msvcrt.dll" () As Integer
Declare Function _getch Lib "msvcrt.dll" () As Integer
Dim outp As System.IO.TextWriter = System.Console.Out
Dim inp As System.IO.TextReader = System.Console.In
Sub Main(ByVal args() As String) '
50
Try
outp.WriteLine("starting Module1.vb")
Dim persons As Persons = New Persons(New Person() { _
New Person("siegfried", "heintze")})
Dim sr As XmlSerializer = New XmlSerializer(GetType([Persons]))'
55
'Dim persons As Persons = CType(sr.Deserialize(inp), Persons)
Dim person As Person
For Each person In persons.persons
person.last = "*" + person.last + "*"
Next '
60
sr.Serialize(outp, persons)
Finally
#If noprompt Then
outp.WriteLine("All done")
#Else '
65
outp.WriteLine("hit any key: ")
_getch()
#End If
End Try
End Sub '
70
End Module