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
See question for answer. (This is at the top of the unanswered list)
Otherwise I found the answer during my investigations in a blog post on elixir-lang.org
For the most commonly used records:
defrecord :xmlElement, Record.extract(:xmlElement, from_lib: "xmerl/include/xmerl.hrl")
defrecord :xmlText, Record.extract(:xmlText, from_lib: "xmerl/include/xmerl.hrl")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With