简单XML解组返回空值

简单XML解组返回空值,xml,go,xml-parsing,Xml,Go,Xml Parsing,我正在尝试在Go中解组一些基本的XML。我已经能够在Go-before中解组非常大的XML文件,所以这里的问题真的让我困惑 解组查找一个项目,这是应该的,但所有值都是其默认值:字符串为空,浮点值为零 任何暗示都会有帮助。谢谢 XML 同样简单的是,节流器结构不导出其字段。因此,将结构更改为具有大写变量使其可访问 <config><throttle delay="20" unit="s" host="feeds.feedburner.com"/></config&g

我正在尝试在Go中解组一些基本的XML。我已经能够在Go-before中解组非常大的XML文件,所以这里的问题真的让我困惑

解组查找一个项目,这是应该的,但所有值都是其默认值:字符串为空,浮点值为零

任何暗示都会有帮助。谢谢

XML

同样简单的是,
节流器
结构不导出其字段。因此,将结构更改为具有大写变量使其可访问

<config><throttle delay="20" unit="s" host="feeds.feedburner.com"/></config>
package main

import (
    "encoding/xml"
    "fmt"
)

// Config allows for unmarshling of the remote configuration file.
type Config struct {
    XMLName    xml.Name     `xml:"config"`
    Throttlers []*Throttler `xml:"throttle"`
}

// Throttler stores the throttle information read from the configuration file.
type Throttler struct {
    host  string  `xml:"host,attr"`
    unit  string  `xml:"unit,attr"`
    delay float64 `xml:"delay,attr"`
}

func main() {

    data := `
        <config><throttle delay="20" unit="s" host="feeds.feedburner.com"/></config>
    `
    config := Config{}
    err := xml.Unmarshal([]byte(data), &config)
    if err != nil {
        fmt.Printf("error: %config", err)
        return
    }
    thr := config.Throttlers[0]
    fmt.Println(fmt.Sprintf("host:%q, unit:%q, delay:%f", thr.host, thr.unit, thr.delay))

}