发布网友 发布时间:2022-04-20 22:11
共1个回答
热心网友 时间:2023-07-17 20:22
func main() {
type Param struct {
XMLName xml.Name `xml:"param"`
Name string `xml:"name,attr"`
Value string `xml:"value,attr"`
}
type People struct {
XMLName xml.Name `xml:"people"`
Name string `xml:"name,attr"`
Params []Param
}
type Include struct {
XMLName xml.Name `xml:"include"`
People People
}
var inc Include
inc.People.Name = "Daniel"
inc.People.Params = []Param{
{Name: "name", Value: "Daniel"},
{Name: "sex", Value: "male"},
{Name: "pwd", Value: "112233"},
{Name: "age", Value: "18"},
{Name: "weight", Value: "120"},
}
if data, err := xml.Marshal(&inc); err != nil {
panic(err)
} else {
fmt.Println(string(data))
}
}