Tag: xmpp4r

使用Ruby,我如何确认XML snippit是否有效?

正如你们中的一些人所知,我正在为StackOverflow聊天系统进行XMPP(Jabber)集成 ,作为使用xmpp4r软件包在Ruby中编写的XMPP组件。 我正在努力解决一个问题(好吧,很多问题,但目前只有一个问题 :-)我正在从聊天中获取JSON提要并提取消息的HTML。 我正在使用Ruby TidyHTML绑定将HTML从JSON转换为XHTML,因此我可以将其作为XMPP消息发送 – 因为XMPP消息只是XML,将HTML转换为XHTMl应该使它成为有效的XML,我可以只需坚持节即可。 对于大多数消息 ,它工作得很好! 但是对于其他消息,它完全窒息 – XMPP服务器关闭流并且脚本停止运行。 (和酒馆里的其他人一起感到不安。好吧,也许不会沮丧 ,但他们会嘲笑我。这让我感到难过!) 我几乎可以肯定,由于某些原因,消息是有效的XML,因此XMPP服务器正在关闭连接,因为它遇到来自Ruby组件的XML流中的解析错误。 以下是一个此类消息的示例: <div class="onebox ob-message"><a class="roomname" href="https://stackoverflow.com/transcript/message/263372"><span title="2010-11-04 19:20:23Z">1 hour ago</span></a>, by <span class="user-name">Fosco</span> <br/><div class="quote"><div class="room-mini"><div class="room-mini-header"><h3><img class="small-site-logo" title="Gaming" alt="Gaming" width="16" height="16" src="http://sstatic.net/gaming/img/favicon.ico" />&nbsp;<span class="room-name"><a href="http://chat.stackexchange.com/rooms/28/minecraft-talk">Minecraft Talk</a></span></h3><div class="room-mini-description">Everything Minecraft, including classic and survival mode</div></div><div class="room-current-user-count" title="current users">9</div><div class="mspark" style="height:25px;width:205px"> […]