Go-如何使用切片将XML解组到容器结构中

I have an XML structure that essentially, includes an array of nodes that should deserialize into a slice of a simple go struct but it's not working. Here's the code I'm working with (the comments show what I expect):

package main

import "fmt"
import "encoding/xml"

func main() {
    c := Conversation{}
    xml.Unmarshal(raw, &c)
    fmt.Println(len(c.Dialog))    // expecting 2, not 0
    fmt.Println(c.Dialog[0].Text) // expecting "Hi", not a panic
}

var raw = []byte(`<conversation>
    <message>
        <text>Hi</text>
    </message>
    <message>
        <text>Bye</text>
    </message>
</conversation>`)

type Conversation struct {
    Dialog []Message `xml:"conversation"`
}

type Message struct {
    XMLName xml.Name `xml:"message"`
    Text    string   `xml:"text"`
}

Why isn't this working?

Playground: http://play.golang.org/p/a_d-nhcfoP

The issue is that your struct field tag for Conversation.Dialog is wrong. The tag should say "message", not "conversation":

type Conversation struct {
    Dialog []Message `xml: "message"`
}

http://play.golang.org/p/5VPUcHRLbe