dongxiaoke2018 2017-12-10 07:09
浏览 32

去XML解组不读取属性

New to Go lang. From the XML, the code unmarshall all values except for attribute. Can someone please advise what I am doing wrong:

package main

import (
    "encoding/xml"
    "fmt"
)

func main() {
    v, _ := GetData()
    fmt.Print(v)
}


type Query struct {
    InstituationList []Instituation `xml:"institution"`
}

type Instituation struct {
    XMLName           xml.Name `xml:"institution"`
    OFXHomeID         string   `xml:"id, attr"`
    Name              string   `xml:"name"`
    FId               string   `xml:"fid"`
    FOrg              string   `xml:"org"`
    URL               string   `xml:"url"`
    OFXHomeIDD         string   `xml:"idd"`
}


func GetData() (*Query, error) {
    fakeXML := `
<?xml version="1.0" encoding="utf-8"?>
<Data>
<institution id="A421">
<idd>423</idd>
<name>ING DIRECT (Canada)</name>
<fid>061400152</fid>
<org>INGDirectCanada</org>
<url>https://ofx.ingdirect.ca</url>
</institution>
</Data>
`

    content := []byte(fakeXML)

    e := new(Query)
    xml.Unmarshal(content, e)

    return e, nil
}
  • 写回答

1条回答 默认 最新

  • doudiaozhi6658 2017-12-10 07:13
    关注

    Resolved. Apparently GO did not like the space in front of attr

    It should be OFXHomeID string xml:"id,attr"

    instead of

    OFXHomeID string xml:"id, attr"

    评论

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度