If you have multiple tags with the same name under the same parent tag, you can always use a slice which will hold all the occurrences of the tag, regardless if they are enumerated next to each other or there are other tags between them.
To be complete, this is the XML fragment you want to parse:
<cap:geocode>
<valueName>FIPS6</valueName>
<value>002090 002290</value>
<valueName>UGC</valueName>
<value>AKZ222</value>
</cap:geocode>
So simply change your geocode
struct from this:
type geocode struct {
ValueName1 string `xml:"valueName"`
Value1 string `xml:"value"`
ValueName2 string `xml:"valueName"`
Value2 string `xml:"value"`
}
To this:
type geocode struct {
ValueNames []string `xml:"valueName"`
Values []string `xml:"value"`
}
And code to print them:
gc := v.Entries[0].Geocode
log.Println(len(gc.Values))
log.Println(gc.ValueNames)
log.Println(gc.Values)
for i := range gc.Values {
fmt.Printf("ValueName=%s, Value=%s
", gc.ValueNames[i], gc.Values[i])
}
Output (try your modified source on the Go Playground):
2009/11/10 23:00:00 2
2009/11/10 23:00:00 [FIPS6 UGC]
2009/11/10 23:00:00 [002090 002290 AKZ222]
ValueName=FIPS6, Value=002090 002290
ValueName=UGC, Value=AKZ222