go docs中的Xml示例已損壞。有誰知道如何使它工作?當我編譯它,結果是:Go XML Unmarshal示例不編譯
xmlexample.go:34: cannot use "name" (type string) as type xml.Name in field value
xmlexample.go:34: cannot use nil as type string in field value
xmlexample.go:34: too few values in struct initializer
下面是相關代碼:
package main
import (
"bytes"
"xml"
)
type Email struct {
Where string "attr";
Addr string;
}
type Result struct {
XMLName xml.Name "result";
Name string;
Phone string;
Email []Email;
}
var buf = bytes.NewBufferString (`
<result>
<email where="home">
<addr>[email protected]</addr>
</email>
<email where='work'>
<addr>[email protected]</addr>
</email>
<name>Grace R. Emlin</name>
<address>123 Main Street</address>
</result>`)
func main() {
var result = Result{ "name", "phone", nil }
xml.Unmarshal (buf , &result)
println (result.Name)
}
感謝您發送補丁 – marketer 2010-01-07 20:14:35