View Source exml_query (exml v4.1.0)
Easy navigation in XML trees
Summary
Functions
Equivalent to path(Element, [{attr, Name}]).
Equivalent to path(Element, [{attr, Name}], Default).
Equivalent to path(Element, [cdata]).
Like path/3
but with default undefined
.
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
Equivalent to path(Element, [{element, Name}]).
Equivalent to path(Element, [{element_with_attr, AttrName, AttrValue}]).
Equivalent to path(Element, [{element_with_ns, Name, NS}]).
Equivalent to path(Element, [{element_with_ns, Name, NS}], Default).
Equivalent to path(Element, [{element_with_ns, NS}], Default).
Equivalent to paths(Element, [{element, Name}]).
Equivalent to paths(Element, [{element_with_attr, AttrName, AttrValue}]).
Equivalent to paths(Element, [{element_with_ns, Name, NS}]).
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.
-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.
-spec path(exml:element() | undefined, 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.
-spec subelement(exml:element(), binary()) -> exml:element() | undefined.
Equivalent to path(Element, [{element, Name}]).
-spec subelement(exml:element(), binary(), Default) -> exml:element() | Default.
Equivalent to path(Element, [{element, Name}], Default).
-spec subelement_with_attr(exml:element(), AttrName :: binary(), AttrValue :: binary()) -> exml:element() | undefined.
Equivalent to path(Element, [{element_with_attr, AttrName, AttrValue}]).
-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).
-spec subelement_with_name_and_ns(exml:element(), binary(), binary()) -> exml:element() | undefined.
Equivalent to path(Element, [{element_with_ns, Name, NS}]).
-spec subelement_with_name_and_ns(exml:element(), binary(), binary(), Default) -> exml:element() | Default.
Equivalent to path(Element, [{element_with_ns, Name, NS}], Default).
-spec subelement_with_ns(exml:element(), binary()) -> exml:element() | undefined.
Equivalent to path(Element, [{element_with_ns, NS}]).
-spec subelement_with_ns(exml:element(), binary(), Default) -> exml:element() | Default.
Equivalent to path(Element, [{element_with_ns, NS}], Default).
-spec subelements(exml:element(), binary()) -> [exml:element()].
Equivalent to paths(Element, [{element, Name}]).
-spec subelements_with_attr(exml:element(), binary(), binary()) -> [exml:element()].
Equivalent to paths(Element, [{element_with_attr, AttrName, AttrValue}]).
-spec subelements_with_name_and_ns(exml:element(), binary(), binary()) -> [exml:element()].
Equivalent to paths(Element, [{element_with_ns, Name, NS}]).
-spec subelements_with_ns(exml:element(), binary()) -> [exml:element()].
Equivalent to paths(Element, [{element_with_ns, NS}]).