继续浏览精彩内容
慕课网APP
程序员的梦工厂
打开
继续
感谢您的支持,我会继续努力的
赞赏金额会直接到老师账户
将二维码发送给自己后长按识别
微信支付
支付宝支付

Golang xml

holdtom
关注TA
已关注
手记 1703
粉丝 240
获赞 991


  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)

    }

©著作权归作者所有:来自51CTO博客作者dccw的原创作品,如需转载,请注明出处,否则将追究法律责任

golangxmlGolang


打开App,阅读手记
0人推荐
发表评论
随时随地看视频慕课网APP