View Source Yex.XmlElement (y_ex v0.7.2)

A shared type that represents an XML node. Provides functionality for manipulating XML elements including child nodes, attributes, and navigation.

Summary

Functions

Returns a stream of all child nodes of the XML element.

Deletes a range of child nodes starting at the specified index. Returns :ok on success, :error on failure.

Retrieves the child node at the specified index. Returns {:ok, node} if found, :error if index is out of bounds.

Similar to fetch/2 but raises ArgumentError if the index is out of bounds.

Returns the first child node of the XML element. Returns nil if the element has no children.

Returns the value of the specified attribute. Returns nil if the attribute does not exist.

Returns a map of all attributes for this XML element.

Returns the tag name of the XML element. Returns nil if the element has no tag.

Inserts a new child node at the specified index. Returns :ok on success, :error on failure.

Inserts a new child node after the specified reference node. If the reference node is not found, inserts at the beginning. Returns :ok on success, :error on failure.

Adds or updates an attribute with the specified key and value. Returns :ok on success, :error on failure.

Returns the number of child nodes in the XML element.

The next sibling of this type. Is null if this is the last child of its parent.

The parent that holds this type. Is null if this xml is a top-level XML type.

The previous sibling of this type. Is null if this is the first child of its parent.

Appends a new child node at the end of the children list. Returns :ok on success, :error on failure.

Removes the attribute with the specified key. Returns :ok on success, :error on failure.

Inserts a new child node at the beginning of the children list. Returns :ok on success, :error on failure.

Types

t()

@type t() :: %Yex.XmlElement{doc: Yex.Doc.t(), reference: reference()}

Functions

as_prelim(xml_element)

@spec as_prelim(t()) :: Yex.XmlElementPrelim.t()

children(xml_element)

@spec children(t()) :: Enumerable.t(t() | Yex.XmlText.t())

Returns a stream of all child nodes of the XML element.

delete(xml_element, index, length)

@spec delete(t(), integer(), integer()) :: :ok | :error

Deletes a range of child nodes starting at the specified index. Returns :ok on success, :error on failure.

fetch(xml_element, index)

@spec fetch(t(), integer()) :: {:ok, t() | Yex.XmlText.t()} | :error

Retrieves the child node at the specified index. Returns {:ok, node} if found, :error if index is out of bounds.

fetch!(map, index)

@spec fetch!(t(), integer()) :: t() | Yex.XmlText.t()

Similar to fetch/2 but raises ArgumentError if the index is out of bounds.

first_child(xml_element)

@spec first_child(t()) :: t() | Yex.XmlText.t() | nil

Returns the first child node of the XML element. Returns nil if the element has no children.

get(xml_element, index)

This function is deprecated. Rename to `fetch/2`.
@spec get(t(), integer()) :: {:ok, t() | Yex.XmlText.t()} | :error

get_attribute(xml_element, key)

@spec get_attribute(t(), binary()) :: binary() | nil

Returns the value of the specified attribute. Returns nil if the attribute does not exist.

get_attributes(xml_element)

@spec get_attributes(t()) :: map()

Returns a map of all attributes for this XML element.

get_tag(xml_element)

@spec get_tag(t()) :: binary() | nil

Returns the tag name of the XML element. Returns nil if the element has no tag.

insert(xml_element, index, content)

@spec insert(t(), integer(), Yex.XmlElementPrelim.t() | Yex.XmlTextPrelim.t()) ::
  :ok | :error

Inserts a new child node at the specified index. Returns :ok on success, :error on failure.

insert_after(xml_element, ref, content)

@spec insert_after(
  t(),
  t() | Yex.XmlText.t(),
  Yex.XmlElementPrelim.t() | Yex.XmlTextPrelim.t()
) :: :ok | :error

Inserts a new child node after the specified reference node. If the reference node is not found, inserts at the beginning. Returns :ok on success, :error on failure.

insert_attribute(xml_element, key, value)

@spec insert_attribute(t(), binary(), binary()) :: :ok | :error

Adds or updates an attribute with the specified key and value. Returns :ok on success, :error on failure.

length(xml_element)

@spec length(t()) :: integer()

Returns the number of child nodes in the XML element.

next_sibling(xml_element)

@spec next_sibling(t()) :: t() | Yex.XmlText.t() | nil

The next sibling of this type. Is null if this is the last child of its parent.

parent(xml_element)

@spec parent(t()) :: t() | Yex.XmlFragment.t() | nil

The parent that holds this type. Is null if this xml is a top-level XML type.

prev_sibling(xml_element)

@spec prev_sibling(t()) :: t() | Yex.XmlText.t() | nil

The previous sibling of this type. Is null if this is the first child of its parent.

push(xml_element, content)

@spec push(t(), Yex.XmlElementPrelim.t() | Yex.XmlTextPrelim.t()) :: :ok | :error

Appends a new child node at the end of the children list. Returns :ok on success, :error on failure.

remove_attribute(xml_element, key)

@spec remove_attribute(t(), binary()) :: :ok | :error

Removes the attribute with the specified key. Returns :ok on success, :error on failure.

to_string(xml_element)

@spec to_string(t()) :: binary()

unshift(xml_element, content)

@spec unshift(t(), Yex.XmlElementPrelim.t() | Yex.XmlTextPrelim.t()) :: :ok | :error

Inserts a new child node at the beginning of the children list. Returns :ok on success, :error on failure.