Search code examples
golinkedin-api

Unmarshal LinkedIn email


How do I unmarchel the follwing LinkedIn api result?

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<email-address>[email protected]</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?


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"`
    }