码迷,mamicode.com
首页 > 其他好文 > 详细

Golang xml

时间:2018-03-07 21:48:42      阅读:104      评论:0      收藏:0      [点我收藏+]

标签:golang

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

标签:golang

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!