1

I have a complex object. I need to parse some information. Since I am new to the ejabberd, I could not find the proper solution.

   {message,<<"92176817070539609217681707064664">>,chat,
                    <<>>,
                    {jid,<<"123456789">>,<<"xmpp-dev1.us">>,
                        <<"909736301959319636867">>,<<"123456789">>,
                        <<"xmpp-dev1.us">>,
                        <<"909736301959319636867">>},
                    {jid,<<"qamember1">>,<<"xmpp-dev1.us">>,
                        <<>>,<<"qamember1">>,<<"xmpp-dev1.us">>,
                        <<>>},
                    [],[],
                    [{text,<<>>,
                         <<"Zz158mDCyNd/2jMgpH4xEHysL8cd+eWuo5v0mrsHmY5X3vy5pnfAl/dtqyq67jla/taMDZY2E5qVU/Ox4lhhyw==">>}],
                    undefined,
                    [{mam_archived,
                         {jid,<<"qamember1">>,
                             <<"xmpp-dev1.us">>,<<>>,
                             <<"qamember1">>,<<"xmpp-dev1.us">>,
                             <<>>},
                         <<"1664341693508458">>},
                     {stanza_id,
                         {jid,<<"qamember1">>,
                             <<"xmpp-dev1.us">>,<<>>,
                             <<"qamember1">>,<<"xmpp-dev1.us">>,
                             <<>>},
                         <<"1664341693508458">>},
                     {chatcontent,<<"0">>,<<>>,<<>>,<<"true">>,<<>>,
                         <<"testmeme">>,<<>>,<<>>,<<"text">>},
                     {chatstate,active},
                     {receipt_request},
                     {timestampmsg,<<>>,<<"1664341693448897">>},
                     {delay,
                         {1664,341693,512794},
                         {jid,<<>>,<<"xmpp-dev1.us">>,<<>>,<<>>,
                             <<"xmpp-dev1.us">>,<<>>},
                         <<"Offline Storage">>}],
                    #{mam_archived => true,stanza_id => 1664341693508458}},

I need chatcontent value from the above.

kumaran
  • 366
  • 1
  • 8

1 Answers1

2

The ejabberd is used the fast_xml library parse XML data. Example:

1> application:start(fast_xml).
ok
2> rr(fxml).
[xmlel]
3> fxml_stream:parse_element(<<"<test>content cdata</test>">>).
#xmlel{name = <<"test">>,attrs = [],
       children = [{xmlcdata,<<"content cdata">>}]}

Here is also example how the Ejabberd team is use it in the source code. After parsing data - you will be able to use a simple pattern matching or you can use internal API of library for get attributes etc.

vkatsuba
  • 1,411
  • 1
  • 7
  • 19