I am using the encoding/xml package in Go and the Encoder example code.
While I am able to produce workable XML, I am unable to add all of the attributes that I need.
As an example, let us use the concept of temperature reporting. What I need is something like this:
<environment>
<temperature type="float" units="c">-11.3</temperature>
</environment>
My struct looks like this:
type climate struct {
XMLName xml.Name `xml:"environment"`
Temperature string `xml:"temperature"`
Type string `xml:"type,attr"`
Units string `xml:"unit,attr"`
}
What I end up with looks like this:
<environment type="float" unit="c">
<temperature>-11.3</temperature>
</environment>
My example code in the Go Playground
How can I format the struct tags to put the attributes in the proper element?