Marshalling XML in GOlang: field is empty (APPEND doesn't work?)

前端 未结 2 811
深忆病人
深忆病人 2021-01-20 14:44

i\'m learning to create XML in Go. Here\'s my code:

type Request struct {
    XMLName       xml.Name        `xml:\"request\"`
    Action        string                


        
2条回答
  •  清歌不尽
    2021-01-20 14:56

    The members that you want to marshal have to be exported (capitalized). Try:

    type point struct {
        Geo    string `xml:"point"`
        Radius int    `xml:"radius,attr"`
    }
    

    From the encoding/xml doc:

    The XML element for a struct contains marshalled elements for each of the exported fields of the struct.

    [..]

    Because Unmarshal uses the reflect package, it can only assign to exported (upper case) fields.

提交回复
热议问题