ElixirXML.Query (ElixirXML v0.0.1)

View Source

A module for querying XML-like structures in Elixir. Provides functions to find nodes using XPath-like syntax, extract text content, and retrieve attributes.

Summary

Functions

Retrieves an attribute from an XML node.

Finds nodes matching the given XPath-like expression.

Extracts all text content from an element and its children.

Functions

attribute(map, name)

@spec attribute(map(), binary()) :: binary() | nil

Retrieves an attribute from an XML node.

Examples

iex> ElixirXML.Query.attribute(%{attributes: %{class: "header"}}, "class")
"header"

find(data, xpath)

@spec find(map() | list(), binary()) :: list()
@spec find(map(), list()) :: list()

Finds nodes matching the given XPath-like expression.

Examples

iex> ElixirXML.Query.find(xml_data, "//book/title")
["Elixir in Action"]

text(list)

@spec text(any()) :: binary()

Extracts all text content from an element and its children.

Examples

iex> ElixirXML.Query.text(%{children: ["Hello", %{children: [" World"]}]})
"Hello World"