I have a print log with packet data and I extract subelement using Packet#message.sub_els
and it gives me array like :
[
{xmlel,<<"delay">>,[{<<"xmlns">>,<<"urn:xmpp:delay">>},{<<"stamp">>,<<"2019-10-24T08:08:15.126+00:00">>}],[]},
{xmlel,<<"type">>,[{<<"xmlns">>,<<"urn:xmpp:media">>}],[{xmlcdata,<<"1">>}]},
{xmlel,<<"media">>,[{<<"xmlns">>,<<"urn:xmpp:data">>}],[{xmlcdata,<<"null">>}]},
{xmlel,<<"extra">>,[{<<"xmlns">>,<<"urn:xmpp:extra">>}],[{xmlcdata,<<"{\"type\":\"chat\",\"id\":\"5d666434ae920b04875c0a57\",\"name\":\"X003\",\"username\":\"x003\",\"status\":\"\",\"profile_picture\":\"\"}">>}]},
{xmlel,<<"request">>,[{<<"xmlns">>,<<"urn:xmpp:receipts">>}],[]},
{xmlel,<<"request">>,[{<<"xmlns">>,<<"urn:xmpp:read">>}],[]}
],
I want to extra type, media, extra. etc.
I Got some methods, using that I have extracted necessary data and attribute value.
AllElm = Packet#message.sub_els,
?INFO_MSG("BinaryData ~p",[fxml:element_to_binary(AllElm)]),
?INFO_MSG("PacketsData ~p",[AllElm]),
%Test = fxml:get_path_s(Packet, [{elem, <<"type">>}]),
Delay = fxml:get_path_s(xmpp:encode(Packet), [{elem,list_to_binary("delay")}, {attr, list_to_binary("stamp")}]),
?INFO_MSG("PacketsDataDelay ~p",[Delay]),
Type = fxml:get_path_s(xmpp:encode(Packet), [{elem,list_to_binary("type")}, cdata]),
?INFO_MSG("PacketsDataType ~p",[Type]),
Media = fxml:get_path_s(xmpp:encode(Packet), [{elem,list_to_binary("media")}, cdata]),
?INFO_MSG("PacketsDataMedia ~p",[Media]),
Extra = fxml:get_path_s(xmpp:encode(Packet), [{elem,list_to_binary("extra")}, cdata]),
?INFO_MSG("PacketsDataExtra ~p",[Extra]),