Search code examples
xmlvb.netxml-deserialization

Deserializing array of items with attribute


I need to deserialize this block of data

<colors>
    <color id='mnemonic1'>RRGGBB1</color>
    <color id='mnemonic2'>RRGGBB2</color>
    <color id='mnemonic3'>RRGGBB3</color>
    <color id='mnemonic4'>RRGGBB4</color>
</colors>

if I define this

<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

I'm able to read 'id' attribute but not 'color' string.
If I define as:

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

I'm able to read only the 'color' value. How can I read both ?


Solution

  • You need to change

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

    to

    <XmlText>Public defColor As String
    

    Anything Inside >(here)< is >(Text)<