I have the following XML, externally defined and outside of my organization's control:
<foo>
<bar>
<zip>zip</zip>
</bar>
<bar>
<zap>zap</zap>
</bar>
</foo>
I am using these structs:
type Foo struct {
XMLName xml.Name `xml:"foo"`
Bar1 Bar1
Bar2 Bar2
}
type Bar1 struct {
XMLName xml.Name `xml:"bar"`
Zip string `xml:"zip"`
}
type Bar2 struct {
XMLName xml.Name `xml:"bar"`
Zap string `xml:"zap"`
}
Because of the conflicting 'bar' name, nothing gets unmarshaled. How can I populate the Bar1 and Bar2 structs?
This is what I have: https://play.golang.org/p/D2IRLojcTB
This is the result I want: https://play.golang.org/p/Ytrbzzy9Ok
In the second one, I have updated the second 'bar' to be 'bar1,' and it all works. I'd rather come up with a cleaner solution that modifying the incoming XML.