Question

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?

Was it helpful?

Solution

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"`
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top