[ejabberd] Pubsub with Ejabberd and exmpp

kael ka-el at laposte.net
Sat May 8 00:42:32 MSD 2010


On 05/07/2010 07:14 PM, shahzad bhatti wrote:
> One more thing, here is the IQ output that is being published:
> Sending : {xmlel,'jabber:client',[],iq,
>               [{xmlattr,undefined,type,<<"set">>},
>                {xmlattr,undefined,to,<<"pubsub.myhost.local">>},
>                {xmlattr,undefined,id,<<"pubsub-1337138231">>}],
>               [{xmlel,'http://jabber.org/protocol/pubsub',[],pubsub,[],
>                    [{xmlel,'http://jabber.org/protocol/pubsub',[],publish,
>                         [{xmlattr,undefined,node,<<"MSFT">>}],
>                         [{xmlel,'http://jabber.org/protocol/pubsub',[],item,
>                              [],
>                              [{xmlcdata,
>                                   <<"{'symbol':'MSFT', 'bid':28.66, 
> 'ask':28.67, 'bidSize':61, 'askSize':13, 'volume':65488100, 
> 'last':28.66}">>}]}]}]}]}
> 
> I am not sure if I am missing anything on the XML.

In this sample, the payload (i.e. the child element of #xmlel{name = 
'item', ns = ?NS_PUBSUB}) is not an #xmlel{} but an #xmlcdata{}.

Try with :

...
Json = "{'symbol':'MSFT', 'bid':28.66, 'ask':28.67, 'bidSize':61, 
'askSize':13, 'volume':'65488100, 'last':28.66}",

Quote = #xmlel{name = 'stocknews', children = [exmpp_xml:cdata(Json)]},

IQ = exmpp_client_pubsub:publish("pubsub."?XMPP_SERVER, Symbol, Quote),
...


As an aside, you might be interested by the deferred XEP-0067: Stock 
Data Transmission <http://xmpp.org/extensions/xep-0067.html>.

-- 
kael



More information about the ejabberd mailing list