View Source exml_query (exml v3.3.4)

Easy navigation in XML trees

Summary

Functions

Query attribute value by name. Returns the attribute value associated with Name if Element contains such attribute. Otherwise returns undefined
Query attribute value by name. Returns the attribute value associated with Name if Element contains such attribute. Otherwise returns Default

See also: attr/2.

Gets the element/attr/cdata contained in the leftmost path Find an element in the xml tree by a path that is pattern-matched against such xml tree structure

Gets the element/attr/cdata in the leftmost possible described path. Like path/2 but returns the given Default if no element matches the path.

See also: path/2.

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

See also: path/2.

Types

Link to this type

element_with_attr_of_value/0

View Source
-type element_with_attr_of_value() :: {element_with_attr, binary(), binary()}.
Link to this type

element_with_name_and_ns/0

View Source
-type element_with_name_and_ns() :: {element_with_ns, binary(), binary()}.
-type element_with_ns() :: {element_with_ns, binary()}.
-type path() ::
    [cdata |
     {element, binary()} |
     {attr, binary()} |
     element_with_ns() |
     element_with_name_and_ns() |
     element_with_attr_of_value()].

Functions

-spec attr(exml:element(), binary()) -> binary() | undefined.
Query attribute value by name. Returns the attribute value associated with Name if Element contains such attribute. Otherwise returns undefined
Link to this function

attr(Xmlel, Name, Other)

View Source
-spec attr(exml:element(), binary(), Other) -> binary() | Other.
Query attribute value by name. Returns the attribute value associated with Name if Element contains such attribute. Otherwise returns Default

See also: attr/2.

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

Gets the element/attr/cdata contained in the leftmost path 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}],
would return <<"Message from bob to alice">>
Link to this function

path(Xmlel, Rest, Other)

View Source
-spec path(exml:element(), path(), Other) -> exml:element() | binary() | Other.
Gets the element/attr/cdata in the leftmost possible described path. Like path/2 but returns the given Default if no element matches the path.

See also: path/2.

-spec paths(exml:element(), path()) -> [exml:element() | binary()].
gets the elements/attrs/cdatas reachable by the described path

See also: path/2.

Link to this function

subelement(Element, Name)

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

subelement(Xmlel, Name, Other)

View Source
-spec subelement(exml:element(), binary(), Other) -> exml:element() | Other.
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.
Link to this function

subelement_with_attr(Element, AttrName, AttrValue, Other)

View Source
-spec subelement_with_attr(Element, AttrName, AttrValue, Other) -> SubElement | Other
                        when
                            Element :: exml:element(),
                            AttrName :: binary(),
                            AttrValue :: binary(),
                            SubElement :: exml:element(),
                            Other :: term().
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.
Link to this function

subelement_with_name_and_ns(Element, Name, NS, Other)

View Source
-spec subelement_with_name_and_ns(exml:element(), binary(), binary(), Other) -> exml:element() | Other.
Link to this function

subelement_with_ns(Element, NS)

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

subelement_with_ns(Xmlel, NS, Other)

View Source
-spec subelement_with_ns(exml:element(), binary(), Other) -> exml:element() | Other.
Link to this function

subelements(Xmlel, Name)

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

subelements_with_attr(Xmlel, AttrName, Value)

View Source
-spec subelements_with_attr(exml:element(), binary(), binary()) -> [exml:element()].
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()].
Link to this function

subelements_with_ns(Xmlel, NS)

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