Golang解析XML属性

huangapple go评论94阅读模式
英文:

Golang Unmarshal XML attributes

问题

我正在尝试从XML中获取一些属性值,但没有成功。
http://play.golang.org/p/a5IqjbH3DV

有人能看出我做错了什么吗?

英文:

I'm trying to get some attribute values out of XML, but without success.
http://play.golang.org/p/a5IqjbH3DV

Can anyone spot of what I'm doing wrong?

答案1

得分: 8

字段应该被导出(以大写字母开头)。

你对Entry的处理是正确的,但对Statistics结构体的处理不正确。

参见:http://play.golang.org/p/cQRGJag313

type Statistics struct {
    TotalUploadViews int `xml:"totalUploadViews,attr"`
    SubscriberCount  int `xml:"subscriberCount,attr"`
}
英文:

The fields should be exported ( start with uppercase )

You did it right for the Entry but not for the Statistics struct

See: http://play.golang.org/p/cQRGJag313

type Statistics struct {
	TotalUploadViews int `xml:"totalUploadViews,attr"`
	SubscriberCount  int `xml:"subscriberCount,attr"`
}

huangapple
  • 本文由 发表于 2013年9月7日 00:50:33
  • 转载请务必保留本文链接:https://go.coder-hub.com/18662730.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定