QuickXml (quick_xml v0.1.0)

View Source

QuickXml is an XML parsing library for Elixir using a Rust NIF powered by the quick-xml crate.

Summary

Functions

Parses an XML string into an Elixir map.

Same as parse/1, but returns the parsed map directly or raises an exception if parsing fails.

Types

parse_error_type()

@type parse_error_type() ::
  :invalid_xml | :unexpected_eof | :malformed_xml | :unknown_error

Functions

parse(xml)

@spec parse(String.t()) :: {:ok, map()} | {:error, {parse_error_type(), String.t()}}

Parses an XML string into an Elixir map.

Parameters

  • xml (string): The XML content to be parsed.

Returns

  • {:ok, map} – If the XML is successfully parsed.
  • {:error, {error_type, message}} – If parsing fails.

Error Types

  • :invalid_xml – The XML structure is incorrect or incomplete.
  • :unexpected_eof – The document ends unexpectedly.
  • :malformed_xml – The XML contains structural issues.
  • :unknown_error – An unspecified error occurred during parsing.

Examples

iex> QuickXml.parse("<root><name>John</name></root>")
{:ok, %{"name" => %{"$text" => "John"}}}

iex> QuickXml.parse("<unclosed>")
{:error, {:malformed_xml, "ill-formed document: start tag not closed: `</unclosed>` not found before end of input"}}

iex> QuickXml.parse("")
{:error, {:unexpected_eof, "no details"}}

parse!(xml)

@spec parse!(String.t()) :: map()

Same as parse/1, but returns the parsed map directly or raises an exception if parsing fails.