Reputation: 21877
How to print the Packet type to raw XML string ? In the example https://github.com/processone/exmpp/blob/master/examples/echo_client.erl the echo_packet(MySession, Packet) -> function takes the parameter Packet which is of xmlel record type. As mentioned in the post https://stackoverflow.com/a/31020654/579689 tried the function xml:element_to_binary/1 but it did not work.
When i tried to print using the following expression
io:format("Received Presence stanza:~n~p~n~n", [xml:element_to_binary({xmlel,<<"message">>,[{<<"xml:lang">>,<<"en">>},{<<"type">>,<<"chat">>},{<<"to">>,<<"x">>},{<<"id">>,<<"aaf6a">>}],[{xmlcdata,<<"\n">>},{xmlel,<<"body">>,[],[{xmlcdata,<<"wewe">>}]},{xmlcdata,<<"\n">>},{xmlel,<<"active">>,[{<<"xmlns">>,<<"http://jabber.org/protocol/chatstates">>}],[]},{xmlcdata,<<"\n">>},{xmlel,<<"time">>,[{<<"xmlns">>,<<"urn:server-time">>},{<<"stamp">>,"2015-06-23T22:48:24Z"}],[]}]})]).
received following error
=ERROR REPORT==== 12-Oct-2015::09:06:01 ===
Error in process <0.30.0> with exit value: {undef,[{xml,element_to_binary,[{xmlel,<<7 bytes>>,[{<<8 bytes>>,<<2 bytes>>},{<<4 bytes>>,<<4 bytes>>},{<<2 bytes>>,<<1 byte>>},{<<2 bytes>>,<<5 bytes>>}],[{xmlcdata,<<1 byte>>},{xmlel,<<4 bytes>>,[],[{xmlcdata,<<4 bytes>>}]},{xmlcdata,<<1 byte>>},{xmlel,<<6 bytes>>,[{<<5 bytes>>,<<37 bytes>>}],[]},{xmlcdata,<<1 byte>>},{xmlel,<<4 bytes>>,[{<<5 bytes>>,<<15 bytes>>},{<<5 bytes>>,"2015-06-23T22:48:24Z"}],[]}]}],[]},{echo_client,loop,1,[{file,"../examples/ech...
Upvotes: 0
Views: 383
Reputation: 12547
Error {undef,[{xml,element_to_binary,[list of N args]}]}
tells you that function xml:element_to_binary/N
is undefined.
Looking through xml module of the project you may try element_to_string
instead of element_to_binary
.
However from the point of efficiency exmpp_xml:document_to_iolist/1
will suit you better
Upvotes: 1