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 2 months ago
JSON representation

Elixir wrapper for xmerl_*

Lists

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]}`.