您的代码中有几处错误。在Go中使用编码包时,所有要编组/解组的字段都必须导出。请注意,结构本身不必导出。
因此,第一步是更改
point结构以导出字段:
type point struct { Geo string `xml:"point"` Radius int `xml:"radius,attr"`}现在,如果要
Geo在点内显示字段,则必须添加
,cdata到xml标记中。最后,无需向
omitempty切片添加关键字。
type Request struct { XMLName xml.Name `xml:"request"` Action string `xml:"action,attr"` Point []point `xml:"point"`}type point struct { Geo string `xml:",chardata"` Radius int `xml:"radius,attr"`}去操场



