View Source exml (exml v4.1.1)

Summary

Types

CDATA record. Printing escaping rules defaults to escaping character-wise.

Printing indentation rule, see to_iolist/2.

Functions

Append new children elements to a element/0.

Return the given element/0 with the specified filter passed over its children.

Insert a child by the given one, if none existed.

Parses a binary or a list of binaries into an XML element/0.

Remove a given attribute from a element/0.

Return the given element/0 without any cdata/0 on its children.

Replace or insert the value of a given attribute.

Replace or insert a child by the given one.

Calculate the length of the original XML payload

Sort in ascending order a list of xml item/0.

Types

attrs/0

-type attrs() :: #{binary() => binary()}.

cdata/0

-type cdata() :: #xmlcdata{content :: iodata(), style :: escaped | cdata}.

CDATA record. Printing escaping rules defaults to escaping character-wise.

Escaping rules:

  • escaped: escapes all characters by regular & control escaping.
  • cdata: wraps the entire string into a <![CDATA[]]> section.

child/0

-type child() :: element() | cdata().

element/0

-type element() :: #xmlel{name :: binary(), attrs :: exml:attrs(), children :: [exml:child()]}.

item/0

-type item() :: element() | cdata() | exml_stream:start() | exml_stream:stop().

prettify/0

-type prettify() :: pretty | not_pretty.

Printing indentation rule, see to_iolist/2.

Functions

append_children(Xmlel, ExtraChildren)

-spec append_children(element(), [element() | cdata()]) -> element().

Append new children elements to a element/0.

filter_children(Xmlel, Pred)

-spec filter_children(element(), fun((element() | cdata()) -> boolean())) -> element().

Return the given element/0 with the specified filter passed over its children.

insert_new_child(Xmlel, NewChild)

-spec insert_new_child(element(), element()) -> element().

Insert a child by the given one, if none existed.

parse(XML)

-spec parse(binary() | [binary()]) -> {ok, element()} | {error, binary()}.

Parses a binary or a list of binaries into an XML element/0.

remove_attr(Xmlel, Key)

-spec remove_attr(exml:element(), binary()) -> element().

Remove a given attribute from a element/0.

remove_cdata(Xmlel)

-spec remove_cdata(element()) -> element().

Return the given element/0 without any cdata/0 on its children.

to_binary(Element)

-spec to_binary(exml_stream:element() | [exml_stream:element()]) -> binary().

Equivalent to erlang:iolist_to_binary(to_iolist(Element, not_pretty)).

to_iolist(Element)

-spec to_iolist(exml_stream:element() | [exml_stream:element()]) -> iodata().

Equivalent to to_iolist(Element, not_pretty).

to_list(Element)

-spec to_list(exml_stream:element() | [exml_stream:element()]) -> string().

Equivalent to erlang:binary_to_list(to_binary(Element)).

to_pretty_iolist(Element)

-spec to_pretty_iolist(exml_stream:element() | [exml_stream:element()]) -> iodata().

Equivalent to to_iolist(Element, pretty).

upsert_attr_value(Xmlel, Key, Value)

-spec upsert_attr_value(element(), binary(), binary()) -> element().

Replace or insert the value of a given attribute.

upsert_child(Xmlel, NewChild)

-spec upsert_child(element(), element()) -> element().

Replace or insert a child by the given one.

xml_size(Rest)

-spec xml_size(item() | [item()]) -> non_neg_integer().

Calculate the length of the original XML payload

xml_sort(Xmlcdata)

-spec xml_sort([item()]) -> [item()];
              (element()) -> element();
              (cdata()) -> cdata();
              (exml_stream:start()) -> exml_stream:start();
              (exml_stream:stop()) -> exml_stream:stop().

Sort in ascending order a list of xml item/0.

Sorting is defined as calling lists:sort/1 at:

  • all the xmlels provided (if there is a list of them) AND
  • all the xmlel elements' attributes recursively (the root and descendants) AND
  • all the xmlel children recursively (the root and descendants).