Sending XHTML over Jabber using xmpppy

落爺英雄遲暮 提交于 2019-12-07 16:25:23

问题


I'm trying to send XHTML (a hyperlink) over Jabber (to Google Talk) using xmpppy, but can't find a good working example... I tried with this:

http://intertwingly.net/blog/2007/08/09/Sending-XHTML-over-Jabber

But didn't work... any ideas??

Thanks in advance!

M


回答1:


Heres a nugget I use to construct a XHTML message (thanks to Thomas Perl / Jabberbot.py)

    html_message = "<b>Test!</b>"

    plain_message = re.sub(r'<[^>]+>', '', html_message)
    message = xmpp.protocol.Message(body=plain_message)
    html = xmpp.Node('html', {'xmlns': 'http://jabber.org/protocol/xhtml-im'})
    html.addChild(node=xmpp.simplexml.XML2Node("<body xmlns='http://www.w3.org/1999/xhtml'>" + html_message.encode('utf-8') + "</body>")) 
    message.addChild(node=html)


来源:https://stackoverflow.com/questions/3310750/sending-xhtml-over-jabber-using-xmpppy

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!