0
votes

I have a child element called Request inside my message element of xmpp packet. Therefore, my packet looks like the below:

<message to="b" from="a" type="chat"> 
    <request xmlns="urn:client:send-ack"></request> 
</message>

I want to match the value of xmlns attribute inside the request element. So I want to do something like

case xml:get_attr_s(<<"xmlns">>, xml_get_subtag(<<Request>>,Packet)) of
   "urn:client:send-receipts" ->
   %% Do something
   ok.

But, obviously this densest work. Whats the best way to do it ?

2
If you really want to use the xml module, then xml:get_tag_attr(<<"xmlns">>, xml:get_subtag(El, <<"request">>)) is the way to go, but (arguably) exml_query:path/2, suggested by Piotr, has a more convenient interface.erszcz

2 Answers

2
votes

Easy and fast way to get this attribute is exml_query:path/2. With it, your case ... of would be following:

case exml_query:path(Stanza, [{element, <<"request">>}, {attr, <<"xmlns">>}]) of
    <<"urn:client:send-receipts">> -> something;
    _ -> something_else
end
1
votes

With latest ejabberd development version, you can do what you want with the following:

xml:get_subtags_with_xmlns(Parsed_xml, <<"request">>, <<"urn:client:send-ack">>).

It will match any number of subtags and return a list.

You need to build ejabberd from source or use the upcoming ejabberd 15.04 version, released before end of month.