View Source exml_query (exml v3.4.1)

Easy navigation in XML trees

Summary

Types

Path definition in an XML query, each step is defined by one of these types.

Functions

Like path/3 but with default undefined.

See also: path/3.

Gets the element/attr/cdata in the leftmost possible described path, or Default if there is no match.

Gets the elements/attrs/cdatas reachable by the described path

See also: path/3.

Types

-type path() ::
    [cdata |
     {attr, binary()} |
     {element, binary()} |
     {element_with_ns, binary()} |
     {element_with_ns, binary(), binary()} |
     {element_with_attr, binary(), binary()}].

Path definition in an XML query, each step is defined by one of these types.

  • cdata: selects cdata from the element
  • {attr, Name}: selects a subelement with the given attribute
  • {element, Name}: selects a subelement with the given name
  • {element_with_ns, NS}: selects a subelement with given namespace
  • {element_with_ns, Name, NS}: selects a subelement with given name and namespace
  • {element_with_attr, AttrName, AttrValue}: selects a subelement with the given attribute and value

Functions

-spec attr(exml:element(), binary()) -> binary() | undefined.

Equivalent to path(Element, [{attr, Name}]).

See also: attr/3.

Link to this function

attr(Xmlel, Name, Default)

View Source
-spec attr(exml:element(), binary(), Default) -> binary() | Default.

Equivalent to path(Element, [{attr, Name}], Default).

-spec cdata(exml:element()) -> binary().

Equivalent to path(Element, [cdata]).

-spec path(exml:element(), path()) -> exml:element() | binary() | undefined.
Like path/3 but with default undefined.

See also: path/3.

Link to this function

path(Xmlel, Rest, Default)

View Source
-spec path(exml:element(), path(), Default) -> exml:element() | binary() | Default.

Gets the element/attr/cdata in the leftmost possible described path, or Default if there is no match.

Find an element in the xml tree by a path that is pattern-matched against such xml tree structure.

For example, given an xml document like
  <message from='alice@localhost' to='alice@localhost/res1' id='id-1'>
    <result xmlns='urn:xmpp:mam:2' id='BGCH2R2950G1'>
      <forwarded xmlns='urn:xmpp:forward:0'>
        <delay xmlns='urn:xmpp:delay' stamp='2021-05-05T08:36:19Z' from='bob@localhost/res1'/>
        <message from='bob@localhost/res1' xmlns='jabber:client' xml:lang='en' to='alice@localhost/res1' type='chat'>
          <body>Message from bob to alice</body>
        </message>
      </forwarded>
    </result>
  </message>
The path
    [{element_with_ns, <<"result">>, <<"urn:xmpp:mam:2">>},
     {element_with_ns, <<"forwarded">>, <<"urn:xmpp:forward:0">>},
     {element_with_ns, <<"message">>, <<"jabber:client">>},
     {element, <<"body">>},
     cdata}],
will return <<"Message from bob to alice">>
-spec paths(exml:element(), path()) -> [exml:element() | binary()].
Gets the elements/attrs/cdatas reachable by the described path

See also: path/3.

Link to this function

subelement(Element, Name)

View Source
-spec subelement(exml:element(), binary()) -> exml:element() | undefined.

Equivalent to path(Element, [{element, Name}]).

Link to this function

subelement(Xmlel, Name, Default)

View Source
-spec subelement(exml:element(), binary(), Default) -> exml:element() | Default.

Equivalent to path(Element, [{element, Name}], Default).

Link to this function

subelement_with_attr(Element, AttrName, AttrValue)

View Source
-spec subelement_with_attr(exml:element(), AttrName :: binary(), AttrValue :: binary()) ->
                        exml:element() | undefined.

Equivalent to path(Element, [{element_with_attr, AttrName, AttrValue}]).

Link to this function

subelement_with_attr(Element, AttrName, AttrValue, Default)

View Source
-spec subelement_with_attr(Element, AttrName, AttrValue, Default) -> SubElement | Default
                        when
                            Element :: exml:element(),
                            AttrName :: binary(),
                            AttrValue :: binary(),
                            SubElement :: exml:element(),
                            Default :: term().

Equivalent to path(Element, [{element_with_attr, AttrName, AttrValue}], Default).

Link to this function

subelement_with_name_and_ns(Element, Name, NS)

View Source
-spec subelement_with_name_and_ns(exml:element(), binary(), binary()) -> exml:element() | undefined.

Equivalent to path(Element, [{element_with_ns, Name, NS}]).

Link to this function

subelement_with_name_and_ns(Element, Name, NS, Default)

View Source
-spec subelement_with_name_and_ns(exml:element(), binary(), binary(), Default) ->
                               exml:element() | Default.

Equivalent to path(Element, [{element_with_ns, Name, NS}], Default).

Link to this function

subelement_with_ns(Element, NS)

View Source
-spec subelement_with_ns(exml:element(), binary()) -> exml:element() | undefined.

Equivalent to path(Element, [{element_with_ns, NS}]).

Link to this function

subelement_with_ns(Xmlel, NS, Default)

View Source
-spec subelement_with_ns(exml:element(), binary(), Default) -> exml:element() | Default.

Equivalent to path(Element, [{element_with_ns, NS}], Default).

Link to this function

subelements(Xmlel, Name)

View Source
-spec subelements(exml:element(), binary()) -> [exml:element()].

Equivalent to paths(Element, [{element, Name}]).

Link to this function

subelements_with_attr(Xmlel, AttrName, Value)

View Source
-spec subelements_with_attr(exml:element(), binary(), binary()) -> [exml:element()].

Equivalent to paths(Element, [{element_with_attr, AttrName, AttrValue}]).

Link to this function

subelements_with_name_and_ns(Xmlel, Name, NS)

View Source
-spec subelements_with_name_and_ns(exml:element(), binary(), binary()) -> [exml:element()].

Equivalent to paths(Element, [{element_with_ns, Name, NS}]).

Link to this function

subelements_with_ns(Xmlel, NS)

View Source
-spec subelements_with_ns(exml:element(), binary()) -> [exml:element()].

Equivalent to paths(Element, [{element_with_ns, NS}]).