View Source Yex.XmlFragment (y_ex v0.7.2)

A shared type to manage a collection of XML nodes. Provides functionality for manipulating XML fragments including child nodes and navigation.

Summary

Functions

Converts the XML fragment to a preliminary representation. This is useful when you need to serialize or transfer the fragment's structure.

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

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 fragment. Returns nil if the fragment has no children.

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.

Returns the number of child nodes in the XML fragment.

Returns the parent node of this fragment. Returns nil if this is a top-level XML fragment.

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

Returns a string representation of the XML fragment and all its child nodes.

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

Types

t()

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

Functions

as_prelim(xml_fragment)

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

Converts the XML fragment to a preliminary representation. This is useful when you need to serialize or transfer the fragment's structure.

children(xml_fragment)

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

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

delete(xml_fragment, index, length)

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

fetch(xml_fragment, index)

@spec fetch(t(), integer()) :: {:ok, Yex.XmlElement.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()) :: Yex.XmlElement.t() | Yex.XmlText.t()

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

first_child(xml_fragment)

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

get(xml_fragment, index)

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

insert(xml_fragment, index, content)

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

insert_after(xml_fragment, ref, content)

@spec insert_after(
  t(),
  Yex.XmlElement.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.

length(xml_fragment)

Returns the number of child nodes in the XML fragment.

parent(xml_fragment)

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

Returns the parent node of this fragment. Returns nil if this is a top-level XML fragment.

push(xml_fragment, content)

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

to_string(xml_fragment)

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

Returns a string representation of the XML fragment and all its child nodes.

unshift(xml_fragment, content)

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