I have to parse many XML documents, I already know the logic to parse the files, but the issue is, the tag for each xml file is different.
This is what I have so far
type Data struct {
Rows []Info `xml:"domain-google.com"` // <- This is custom and needs to change (e.g. the next xml doc tag will be `xml:"domain-facebook.com"`
}
type Info struct {
Domain string `xml:"domain"`
}
// example logic for parsing xml
xmlFile, err := http.Get("somefiles.xml")
if err != nil { fmt.Println(err) }
var data Data
if err = xml.NewDecoder(xmlFile.Body).Decode(&data); err != nil {
fmt.Println(err)
}
for _, rows := range data.Rows {
fmt.Println(rows.Domain)
}
example xml documents
<response>
<!-- This tag is what is custom every time -->
<domain-google.com>
<domain>google.com</domain>
</domain-google.com>
</response>
<response>
<!-- This tag is what is custom every time -->
<domain-facebook.com>
<domain>facebook.com</domain>
</domain-facebook.com>
</response>
Any idea how to tackle this issue?
Thank you in advanced.