使用属性反序列化项目数组

时间:2017-02-02 17:30:31

标签: xml vb.net xml-deserialization

我需要反序列化这个数据块

<XmlArray("colors")> <XmlArrayItem("color")> Public colors() As DefColor
..
Public Class DefColor
    <XmlAttribute("id")> Public id As String
    <XmlElement("color")> Public defColor As String
End Class

如果我定义了这个

<XmlArray("colors")><XmlArrayItem("color")> Public colors() As String

我能够阅读&#39; id&#39;属性但不是&#39;颜色&#39;字符串。
如果我定义为:

Public Function CONCAT_SQL(strSQL As String) As String

Dim r As ADODB.Recordset
Dim a As Variant

Set r = New ADODB.Recordset
r.Open strSQL, CurrentProject.Connection, 1

a = Split(r.GetString, Chr(13))
ReDim Preserve a(UBound(a) - 1)

CONCAT_SQL = Join(a, ",")

End Function

我只能阅读&#39;颜色&#39;值。我怎么能同时阅读?

1 个答案:

答案 0 :(得分:1)

您需要更改

<XmlElement("color")> Public defColor As String

<XmlText>Public defColor As String

内部任何内容&gt;(此处)&lt;是&gt;(文字)&lt;