由于有多个列表,我在反序列化此表时遇到了麻烦,我知道我的 trs 重复时需要一个列表,而且我的 tds 也需要一个列表,因为它们也重复,当尝试读取的值时出现问题tds,因为我有它的列表格式。
这是我的xml:
<table>
<tr>
<td>1</td>
<td>2</td>
</tr>
<tr>
<td>3</td>
<td>4</td>
</tr>
</table>
还有我的课:
Public Class table
Private newtr As List(Of tr)
<XmlElement()> _
Public Property tr() As List(Of tr)
Get
Return newtr
End Get
Set(ByVal value As List(Of tr))
newtr = value
End Set
End Property
End Class
Public Class tr
Private newtd As List(Of td)
<XmlElement()> _
Public Property td() As List(Of td)
Get
Return newtd
End Get
Set(ByVal value As List(Of td))
newtd = value
End Set
End Property
End Class
Public Class td
Private newvalue As String
<XmlElement()> _
Public Property td() As String
Get
Return newvalue
End Get
Set(ByVal value As String)
newvalue = value
End Set
End Property
End Class
我的代码:
Public Sub test2()
Dim rr As New table()
Dim xx As New XmlSerializer(rr.GetType)
Dim objStreamReader2 As New StreamReader("table.xml")
Dim rr2 As New table()
rr2 = xx.Deserialize(objStreamReader2)
For Each ii As tr In rr2.tr
MsgBox(ii.td)
Next
End Sub
那么关于如何获得 tds 中的每一个值的任何想法?谢谢!