解析 LinkedIn 邮箱

huangapple go评论135阅读模式
英文:

Unmarshal LinkedIn email

问题

如何解析以下LinkedIn API结果?

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

你可以参考这个链接:http://golang.org/pkg/encoding/xml/#example_Unmarshal
我尝试过了,但只能获取到根节点的名称。

你可以使用以下代码来解析:

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

顺便说一句,我不确定LinkedIn返回的是否是有效的XML格式。

英文:

How do I unmarchel the follwing LinkedIn api result?

&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;yes&quot;?&gt;
&lt;email-address&gt;...@gmail.com&lt;/email-address&gt;

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

type UserL struct {
	XMLName xml.Name `xml:&quot;email-address&quot;`
}

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

答案1

得分: 3

你需要告诉解析器你期望的是字符数据(在这里可以看到工作代码:http://play.golang.org/p/3J57mjeWob)。

type UserL struct {
    XMLName xml.Name `xml:"email-address"`
    EmailAddr string   `xml:",chardata"`
}
英文:

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:&quot;email-address&quot;`
    EmailAddr string   `xml:&quot;,chardata&quot;`
}

huangapple
  • 本文由 发表于 2014年1月5日 07:48:43
  • 转载请务必保留本文链接:https://go.coder-hub.com/20928203.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定