Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/pwoolcoc/exmerl
Elixir wrapper for xmerl_*
https://github.com/pwoolcoc/exmerl
Last synced: about 1 month ago
JSON representation
Elixir wrapper for xmerl_*
- Host: GitHub
- URL: https://github.com/pwoolcoc/exmerl
- Owner: pwoolcoc
- Created: 2014-05-13T20:52:10.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2017-01-23T15:07:02.000Z (almost 8 years ago)
- Last Synced: 2024-10-11T23:12:41.868Z (2 months ago)
- Language: Elixir
- Size: 10.7 KB
- Stars: 12
- Watchers: 3
- Forks: 2
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
- freaking_awesome_elixir - Elixir - Elixir wrapper for xmerl. (XML)
- fucking-awesome-elixir - exmerl - Elixir wrapper for xmerl. (XML)
- awesome-elixir - exmerl - Elixir wrapper for xmerl. (XML)
README
# Exmerl
A wrapper for the xmerl\_\* suite of modules, though at the moment all
you can do is parse and use xpaths to select nodes.## Usage
Currently it is possible to parse XML from a file or string using either `from_file/1,2`,
`from_string/1,2` or `parse/1,2`. They all accept an optional Keyword
list as the second argument. Possible options can be found in the erlang
documentation for the xmerl\_\* modules.iex(1)> # you can pass parse/1,2 a filename or an xml string
iex(2)> Exmerl.parse("test.xml")
{{:xmlElement, :root, :root, [], {:xmlNamespace,...
...
...
iex(3)> {doc, rest} = Exmerl.from_string("""Test""")
{{:xmlElement, :root, :root, [], {:xmlNamespace,...
...
...You can traverse the document by using xpath selectors, and the
Exmerl.XPath.find function. `find/2,3,4,5` takes an XML document (or a
`{doc, rest}` pair as shown above), an xpath selector, and optional
`node`, `parent`, and a Keyword list of options. `find` will accept a
`{doc,rest}` pair to make it easier to pipe the output of `parse` into
`find`:iex(1)> Exmerl.parse("test.xml") |>
...(1)> Exmerl.XPath.find("//some-node-name")
{[{:xmlElement, ...
...
...In this case, instead of returning `[result_term]`, it will return
`{[result_term], [rest]}`.