I have an output :
MysqlResult = {selected,["id","first_name","last_name"],
[{1,"Matt","Williamson"},
{2,"Matt","Williamson2"}]}
how to make it look like :
XML = "
<result id='1'>
<first_name>Matt</first_name>
<last_name>Williamson</last_name>
</result>
<result id='2'>
<first_name>Matt</first_name>
<last_name>Williamson2</last_name>
</result>"
I am looking for a smart way for placing it into IQ ( ejabberd )
IQ#iq{type = result, sub_el =
[{xmlelement, "result",
[{"xmlns", ?NS_NAMES}],
[{xmlelement, "userinfo", [],
[{xmlcdata,"???"?? }]}]}]}
The xmerl solution is absolutely fine, and probably the way to go if this is a one-off type thing.
However, if you are writing an xmpp client, even a simple one, consider using exmpp - https://github.com/processone/exmpp . You can use some of the tactics to extract data and generate XML, but in general, the helper functions (most likely within the exmpp_iq and exmpp_stanza modules) will be very handy.
exmpp isn't going anywhere either -- the alpha of ejabberd3 is using it internally (finally)
First extract the results element from the tuple:
Then convert it to ejabberd's internal XML format with a list comprehension:
And insert it into your IQ record:
(assuming that you want the
<result/>
elements as children of the<userinfo/>
element)Try to use --xml and --execute option in mysql command line client.
mysql client
Use
xmerl
to create XML in Erlang: