'Ejabberd/Erlang get custom XML Element from Packet

Ejabberd newbie here... I am trying to use Ejabberd API to send in custom XML for message statuses from an external service. This external service uses the Ejabberd 'send_stanza' back to the Ejabberd to alert the xmpp user the status of the message. When I send in a received message type or error message type, all is good.

What I am trying to do now is to add a custom tag so that the module (based on filter_packet) can make decisions based on the "app" sending in the packet.

So assume I have this API call:

{
  "from": "[email protected]",
  "to": "[email protected]/gajim.LWMH0CHS",
  "stanza": "<message type='error' from='[email protected]' id='f8972327-85e3-4095-a9e3-4761b66bf503' to='[email protected]/gajim.LWMH0CHS'><origin-id xmlns='urn:xmpp:sid:0' id='f8972327-85e3-4095-a9e3-4761b66bf503'/><request xmlns='urn:xmpp:receipts'/><markable xmlns='urn:xmpp:chat-markers:0'/><appsource appid='external_app'/></message>"
}

So notice this part of the message:

 <appsource appid='external_app'/>

Here is a snippet of the module:

check_packet(Packet) ->
?INFO_MSG("check_packet Packet ~p",[Packet]),

El = xmpp:encode(Packet),
Source = fxml:get_path_s(El, [{elem, "appsource"}, {attr, "appid"}]),
?INFO_MSG("check_packet Source=~p",[Source]).

The Source variable always returns: <<>>

Any help would be greatly appreciated. Thanks



Solution 1:[1]

Right, instead of strings, use binaries:

Source = fxml:get_path_s(El, [{elem, <<"appsource">>}, {attr, <<"appid">>}]),

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Badlop