RustyXML.SimpleForm (RustyXML v0.2.3)

Copy Markdown View Source

Parse XML into a simple tree of nested tuples.

Drop-in replacement for Saxy.SimpleForm.

The simple form represents XML as:

{tag_name, attributes, children}

Where:

  • tag_name is a string
  • attributes is a list of {name, value} tuples
  • children is a list of child elements or text strings

Examples

RustyXML.SimpleForm.parse_string("<root><item id=\"1\">text</item></root>")
#=> {:ok, {"root", [], [{"item", [{"id", "1"}], ["text"]}]}}

Summary

Functions

Parse a stream of XML chunks into simple form.

Parse an XML string into simple form.

Types

element()

@type element() :: {String.t(), [{String.t(), String.t()}], [element() | String.t()]}

Functions

parse_stream(stream, opts \\ [])

@spec parse_stream(
  Enumerable.t(),
  keyword()
) :: {:ok, element()} | {:error, any()}

Parse a stream of XML chunks into simple form.

Accumulates all chunks in Rust, then validates, indexes, and builds the SimpleForm tree in one pass. Minimal BEAM memory during accumulation.

Examples

File.stream!("large.xml", [], 64 * 1024)
|> RustyXML.SimpleForm.parse_stream()
#=> {:ok, {"root", [], [...]}}

parse_string(xml, opts \\ [])

@spec parse_string(
  String.t(),
  keyword()
) :: {:ok, element()} | {:error, any()}

Parse an XML string into simple form.

Returns {:ok, root_element} on success, {:error, exception} on failure.

Options

  • :cdata_as_characters - Merge CDATA into text content (default: true)