There's a struct:
type S struct {
Value string `xml:"value,attr"`
}
I want to encode the struct to an XML file. However, I want the attribute name of Value
to be different in each file:
s1 := S{
Value: "One"
}
should encode to:
<S value="One"></S>
and
s2 := S{
Value: "Two"
}
should encode to:
<S category="Two"></S>
So, I need either to change the XML element name somehow, or change the tag on the field. Is this possible?
I checked reflect
(https://golang.org/pkg/reflect/#Value.FieldByName), but since FieldByName
returns a value type and there are no Set
methods, I don't think it's possible to use reflection.