A very simple/rough draft XML parser in Elixir. I'm currently using xmerl_scan.string
to parse the xml. It works for parsing rss feeds.
Quinn.parse("<head><title short_name = \"yah\">Yahoo</title><title:content>Bing</title:content></head>")
Calling parse on the xml will produce
[%{attr: [], name: :head,
value: [%{attr: [short_name: "yah"], name: :title, value: ["Yahoo"]},
%{attr: [], name: :"title:content", value: ["Bing"]}]}]
Suppose you want to find all the body nodes from this structure:
structure = %{attr: [],
name: :html,
value: [%{attr: [], name: :head, value: ["title"]},
%{attr: [], name: :title, value: []},
%{attr: [], name: :body, value: ["body1", "body2"]},
%{attr: [], name: :footer, value: [%{attr: [], name: :line, value: ["this"]}]},
%{attr: [], name: :body, value: [%{attr: [], name: :line, value: ["that"]}]},
%{attr: [], name: :"content:encoded", value: ["<p>comet!!</p>"]}]}
You can call
Quinn.find(structure, :body)
This will be the result:
[%{attr: [], name: :body, value: ["body1", "body2"]},
%{attr: [], name: :body, value: [%{attr: [], name: :line, value: ["that"]}]}]
Or given the structure above, you want to find the node line
inside body
, then you can invoke it like this:
Quinn.find(structure, [:body, :line])
The result will be
[%{attr: [], name: :line, value: ["that"]}]
Please refer to the tests if you want to see more example on how it is used.
Please let me know if you come across any problem. I'm still new to Elixir so feel free to contribute or clean up the code.
Quinn source code is released under Apache 2 License. Check LICENSE file for more information.