2 回答
TA贡献1875条经验 获得超5个赞
type Result struct {
Claims []Claim `xml:"claim"`
}
type Claim struct {
ClaimText []ClaimText `xml:"claim-text"`
}
type ClaimText struct {
Value string `xml:",chardata"`
ClaimText []ClaimText `xml:"claim-text"`
}
https://play.golang.org/p/uueAiwG84LH
如果你想摆脱空白,你可以实现解封接口:
func (t *ClaimText) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error {
type T ClaimText
if err := d.DecodeElement((*T)(t), &start); err != nil {
return err
}
t.Value = strings.TrimSpace(t.Value)
return nil
}
https://play.golang.org/p/2I1meeBm0pu
TA贡献1852条经验 获得超1个赞
看看这个在线工具,它生成以下结构:
type Claims struct {
XMLName xml.Name `xml:"claims"`
Text string `xml:",chardata"`
Claim []struct {
Text string `xml:",chardata"`
ClaimText struct {
Text string `xml:",chardata"`
ClaimText []struct {
Text string `xml:",chardata"`
ClaimText []string `xml:"claim-text"`
} `xml:"claim-text"`
} `xml:"claim-text"`
} `xml:"claim"`
}
- 2 回答
- 0 关注
- 98 浏览
添加回答
举报