不是一个完美的解决方案,但您可以使用这样的 xpath
//channel/item/description[1]/text()[16]和//channel/item/description[1]/text()[24]
提取的字符串开头包含 urls + 引号,因此您可以使用列表匹配语法来切断引号:[_|Url] = ...
所以使用这个:[{_,_,_,_,[_|U1],_}] = xmerl_xpath:string("//channel/item/description[1]/text()[16]", Xml).将 U1 与第一个 url 绑定。
在外壳中测试:
11> [{_,_,_,_,[_|U1],_}] = xmerl_xpath:string("//channel/item/description[1]/text()[16]", Xml).
[{xmlText,[{description,5},{item,5},{channel,1},{rss,1}],
16,[],"\"http://www.reddit.com/user/escaped_reddit",text}]
12>
12> U1.
"http://www.reddit.com/user/escaped_reddit"
13>
13>
13> [{_,_,_,_,[_|U2],_}] = xmerl_xpath:string("//channel/item/description[1]/text()[24]", Xml).
[{xmlText,[{description,5},{item,5},{channel,1},{rss,1}],
24,[],
"\"http://www.reddit.com/r/erlang/comments/y62wf/how_to_use_ranch/",
text}]
14>
14> U2.
"http://www.reddit.com/r/erlang/comments/y62wf/how_to_use_ranch/"