私は、GoとEncoder example codeでencoding/xmlパッケージを使用しています。Goの要素にXML属性を追加する方法は?
私は実行可能なXMLを作成できますが、必要なすべての属性を追加できません。
例として、温度レポートの概念を使用しましょう。私に必要なのは、このようなものです:
<environment>
<temperature type="float" units="c">-11.3</temperature>
</environment>
私の構造体は次のようになります。
<environment type="float" unit="c">
<temperature>-11.3</temperature>
</environment>
My example code in the Go Playground
方法:私はこのようなルックスで終わる何
type climate struct {
XMLName xml.Name `xml:"environment"`
Temperature string `xml:"temperature"`
Type string `xml:"type,attr"`
Units string `xml:"unit,attr"`
}
適切な要素に属性を入れるためにstructタグをフォーマットできますか?