SimpleXml (simple_xml v0.1.2)

This is a thin wrapper around the saxy library. It leverages the DOM generated by saxy's SimpleForm parser and defines some basic operations on the DOM via the XmlNode module.

The main benefit of using saxy's SimpleForm parsing is that it gives us a string presentation of the XML DOM, without exposing the users of this library with the atom exhaustion vulernability of the xmerl library and any parsers based on it.

Summary

Functions

Parses an XML string to return a tuple representing the XML node.

Types

Link to this type

xml_attribute()

@type xml_attribute() :: {String.t(), String.t()}
@type xml_node() :: {String.t(), [xml_attribute()], [tuple()]}

Functions

@spec parse(String.t()) :: {:ok, xml_node()} | {:error, Saxy.ParseError.t()}

Parses an XML string to return a tuple representing the XML node.

Examples

Well-formed XMLs are successfully parsed

iex> SimpleXml.parse(~S{<foo attr1="value1" attr2="value2">body</foo>})
{:ok, {"foo", [{"attr1", "value1"}, {"attr2", "value2"}], ["body"]}}

Malformed XMLs result in an error

iex> SimpleXml.parse("<foo")
{:error, %Saxy.ParseError{reason: {:token, :name_start_char}, binary: "<foo", position: 4}}