I'm forced to work with some poorly designed XML, I'm trying to read this XML into a Go structure. Here's some sample data:
<?xml version="1.0" encoding="UTF-8"?>
<dictionary>
<direction from="lojban" to="English">
<valsi word="cipni" type="gismo">
<rafsi>cpi</rafsi>
<definition>x1 is a bird of species x2</definition>
<notes></notes>
</valsi>
...
</direction>
<direction from="English" to="lojban">
<nlword word="eagle" valsi="atkuila" />
<nlword word="hawk" sense="bird" valsi="aksiptrina" />
...
</direction>
</dictionary>
My issue is I can either read in nodes or because they both contain the attribute "word":
main.NLWord field "Word" with tag "word,attr" conflicts with field "Valsi" with tag "word,attr"
I'm starting to think unmarshalling may be the wrong approach as I'd ideally structure the data differently. Should I read the XML in using some other method and build up data structures manually?
type Valsi struct {
Word string `xml:"word,attr"`
Type string `xml:"type,attr"`
Def string `xml:"definition"`
Notes string `xml:"notes"`
Class string `xml:"selmaho"`
Rafsi []string `xml:"rafsi"`
}
//Whoever made this XML structure needs to be painfully taught a lesson...
type Collection struct {
From string `xml:"from"`
To string `xml:"to"`
Valsi []Valsi `xml:"valsi"`
}
type Vlaste struct {
Direction []Collection `xml:"direction"`
}
var httpc = &http.Client{}
func parseXML(data []byte) Vlaste {
vlaste := Vlaste{}
err := xml.Unmarshal(data, &vlaste)
if err != nil {
fmt.Println("Problem Decoding!")
log.Fatal(err)
}
return vlaste
}