14

How to make this kind of record pattern matching in Elixir?

[ #xmlText{value=Rank} ]  = xmerl_xpath:string("//SalesRank/text()", Xml),

Bonus: rewrite this example from Dave Thomas's blog in Elixir.


Update:

found what was my problem. You have to use

defrecord :xmlText, Record.extract(:xmlText, from_lib: 'xmerl/include/xmerl.hrl')

to extract the record from XMerL lib into your program as stated here. Then the .value syntax works and the line can be written as follows:

rank = Enum.first(xmerl_xpath.string('//SalesRank/text()', xml)).value
4

1 回答 1

2

请参阅问题以获取答案。(这是未答复列表的顶部)

否则,我在 elixir-lang.org 上的一篇博文中进行调查时找到了答案

对于最常用的记录:

defrecord :xmlElement, Record.extract(:xmlElement, from_lib: "xmerl/include/xmerl.hrl")
defrecord :xmlText, Record.extract(:xmlText, from_lib: "xmerl/include/xmerl.hrl")
于 2014-02-19T12:02:25.410 回答