I started a project to process XML input, I ran into a problem with the unmarshal method. I'm trying to umarshal the XML below into a struct. The are multiple 'values' tag, which is fine, but within the 'values' tag there can be either one 'value' tag with a value. Or there are multiple 'value' tags with a 'key'&'value' tag inside. I'm trying to capture this in a Go struct, but no luck so far..
<lines>
<values>
<key>Key_1</key>
<value>Value_1</value>
</values>
<values>
<key>Key_2</key>
<value>
<key>NestedKey_1</key>
<value>NestedValue_1</value>
</value>
<value>
<key>NestedKey_2</key>
<value>NestedValue_2</value>
</value>
</values>
Go struct:
type Value struct {
Key string `xml:"key"`
Value string `xml:"value"`
}
type Values struct {
Key string `xml:"key"`
Value []Value `xml:"value"`
}
type Lines struct {
Values []Values `xml:"values"`
}
When I print the unmarshal output, I do see Key_1 and Key_2 and the nested key-value pairs, but I don't see Value_1 in the output. Which is obvious since it's a string and not an array, anyone an idea how to work around this?
Playground: http://play.golang.org/p/I4U0lhPt5U
Value
. It just has a value. Is that even valid? – evanmcdonnal