首页 > 其他 > 详细

Golang xml

时间:2018-03-07 21:33:44      阅读:250      评论:0      收藏:0      [点我收藏+]
package main import ( "encoding/xml" "fmt" "os" ) type Address struct { City, State string } type Person struct { XMLName xml.Name `xml:"person"` Id int `xml:"id,attr"` FirstName string `xml:"name>first"` LastName string `xml:"name>last"` Age int `xml:"age"` Height float32 `xml:"height,omitempty"` Married bool Address Comment string `xml:",comment"` } func main() { v := &Person{Id: 13, FirstName: "John", LastName: "Doe", Age: 42} v.Comment = " Need more details. " v.Address = Address{"Hanga Roa", "Easter Island"} output, err := xml.MarshalIndent(v,""," ") if err != nil { fmt.Printf("error: %v\n", err) } os.Stdout.Write(output) }

Golang xml

原文:http://blog.51cto.com/13187574/2083965

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!