質問

How do I unmarchel the follwing LinkedIn api result?

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<email-address>...@gmail.com</email-address>

http://golang.org/pkg/encoding/xml/#example_Unmarshal tried it but I get only the root name.

type UserL struct {
    XMLName xml.Name `xml:"email-address"`
}

PS I wonder if it is actually valid xml LinkedIn returns?

役に立ちましたか?

解決

You need to tell the parser that you're expecting character data (see working code here: http://play.golang.org/p/3J57mjeWob).

type UserL struct {
    XMLName xml.Name `xml:"email-address"`
    EmailAddr string   `xml:",chardata"`
}
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top