如何生成下面格式的 xml 文件

发布网友 发布时间: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))
  }
  }

声明声明:本网页内容为用户发布,旨在传播知识,不代表本网认同其观点,若有侵权等问题请及时与本网联系,我们将在第一时间删除处理。E-MAIL:11247931@qq.com