无法读取使用asmack XMPP库为Android时,自定义属性从消息标记? [英] Cannot Read Custom Attributes From Message TAG when using asmack XMPP library for android?

查看:252
本文介绍了无法读取使用asmack XMPP库为Android时,自定义属性从消息标记?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我想收到这样我可以把它送到我的XML解析器发送从XMPP服务器端的XML。

This is the XML sent From XMPP Server Side that i want to recieve so that i can send it to my XML parser.

<message to="39@domainname.com/smack" chat_id="73392" 
       custom_packet="true" user_id="44" manager_id="39" time_stamp="0" website_id="0" 
       visitor_name="John" end_time="False" xml:lang="en-us" type="groupchat" 
       from="room73392@conference.domainname.com/39">
       <body>Hello</body> 
       <x xmlns="http://jabber.org/protocol/muc#user"> 
       <status xmlns="" code="0"/>   
       </x></message>

这是我Recieving一个示例XML。
当我使用p.toXML(); //分组P

This Is a sample XML that i am Recieving. When i use p.toXML(); //Packet p

 <message to="44@domainname.com/Smack" 
    from="room73407@conference.domainname.com/Visitor1171" type="groupchat">
    <body>Hello</body>
    <delay xmlns="urn:xmpp:delay"></delay>
    <x xmlns="jabber:x:delay" stamp="20120917T05:57:19" 
    from="4732abb5@domainname.com/4732abb5">
    </x></message>

我一直在使用XMPP服务器刚刚起步。因此,任何将指导鸭preciated。

I have Just started using XMPP server. So any Guidance Will be Appreciated.

推荐答案

无需修改源$ C ​​$ C你不能做到这一点的拍击(因此aSmack)。它只会解析一个标准的消息节,让你所有的自定义属性将被忽略。在XMPP正确的方法是创建对标准的扩展包,不能修改它们。如果您对正在从服务器发送的内容控制,那么你应该你的方法改为添加自定义扩展到信息,从而改变这种

You can't do this in Smack (and therefore aSmack) without modifying the source code. It will only parse a standard Message stanza, so all your custom attributes will be ignored. The proper approach in XMPP is to create extensions to the standard packets, not modify them. If you have control over what is being sent from the server, then you should change your approach to adding a custom extension to the message, thus changing this

<message to="39@domainname.com/smack" chat_id="73392" 
 custom_packet="true" user_id="44" manager_id="39" time_stamp="0" 
 website_id="0" visitor_name="John" end_time="False" xml:lang="en-us" 
 type="groupchat" from="room73392@conference.domainname.com/39">
   <body>Hello</body>
   <x xmlns="http://jabber.org/protocol/muc#user">
      <status xmlns="" code="0"/>
   </x>
</message>

这个

<message to="39@domainname.com/smack" chat_id="73392" xml:lang="en-us" 
 type="groupchat" from="room73392@conference.domainname.com/39">
   <body>Hello</body>
   <x xmlns="http://jabber.org/protocol/muc#user">
      <status xmlns="" code="0"/>
   </x>
   <custom xmlns="my:namespace:custom" user_id="44" manager_id="39" time_stamp="0" 
 website_id="0" visitor_name="John" end_time="False"/>
</message>

然后你就可以很容易地编写自己的提供解析自定义数据包扩展,通过调用检索您的自定义对象(由解析器创建)

Then you can easily write your own provider to parse the custom packet extension and simply retrieve your custom object (created by your parser) by calling

MyExtension customStuff = message.getExtension("my:namespace:custom");

您可以检查出的 EmbeddedExtensionProvider 以非常轻松编写人员。

You can check out the EmbeddedExtensionProvider to very easily write your provider.

这篇关于无法读取使用asmack XMPP库为Android时,自定义属性从消息标记?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆