SkillAgentSearch skills...

Exmerl

Elixir wrapper for xmerl_*

Install / Use

/learn @pwoolcoc/Exmerl
About this skill

Quality Score

0/100

Supported Platforms

Universal

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("""<?xml version="1.0" encoding="utf-8" ?><rootnode>Test</rootnode>""")
{{: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]}.

Related Skills

View on GitHub
GitHub Stars12
CategoryDevelopment
Updated3y ago
Forks2

Languages

Elixir

Security Score

60/100

Audited on Dec 4, 2022

No findings