如何在Go中构建三层XML

I`ve do enough homework that i know how to build a one laver xml just like

<name>aaa</name><id>233</id>

But im puzzled by how to build a three or more layers xml in go now.

<Person>
    <Id>233</Id>
    <Information>
        <name>aaa</name>
    </Information>
</Person>

I know i can use Person.Id = 233 but i cant do more. Need help, im a new, thks a lot!

You just have to nest the structs. You can go as deep as you want e.g. Info could have yet another struct inside it.

https://play.golang.org/p/pADEJXj8En

type Person struct {
    Id int
    Information Info
}

type Info struct {
    Name string `xml:"name"`
}

func main() {
    p := &Person{
        Id: 233,
        Information: Info {
            Name: "aaa",
        },
    }
    dat, err := xml.Marshal(p)
    if err != nil {
        return
    }
    fmt.Println(string(dat))
}

For further information, refer to the documentation https://godoc.org/encoding/xml#Marshal and the example given there: https://godoc.org/encoding/xml?play=MarshalIndent