type MyData struct {
Name string
Attributes map[string]string
}
<name atr1="v1" atr2="v2"/>
package main
import (
"encoding/xml"
"fmt"
)
type MyData struct {
XMLName xml.Name
Attributes []xml.Attr `xml:",attr"`
}
func main() {
v := MyData{
XMLName: xml.Name{Local: "somename"},
Attributes: []xml.Attr{
{Name: xml.Name{Local: "attr1"}, Value: "val1"},
{Name: xml.Name{Local: "attr2"}, Value: "val2"},
},
}
rawData, _ := xml.Marshal(v)
fmt.Println(string(rawData))
}