如何使用Smack库发送自定义XML数据? [英] How to send custom XML data using the Smack library?

查看:62
本文介绍了如何使用Smack库发送自定义XML数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Java中的Smack API连接到我的XMPP服务器.

I'm using the Smack API in Java to connect to my XMPP server.

我要发送这样的自定义消息包:

I want to send a customized message packet like this:

<message to="you@MyServer.com" type="chat" MYFIELD="custom stuff">
    <body> hi </body>
    <CUSTOM_STANZA A="..." B="..."> 
        C="..." 
        D="..."
    </CUSTOM_STANZA>
</message>

我猜我创建了自己的Packet,并以toXML()方法返回此XML.但这似乎不起作用.

I'm guessing that I create implement my own Packet with that returns this XML in it's toXML() method. But that doesn't seem to work.

任何帮助将不胜感激.

推荐答案

您需要定义一个自定义类,该类应实现ExtensionElement (由@ )

You need to define a custom class that should implements ExtensionElement (as menitioned by @Flow)

在此答案中可以找到产生以下节的非常详细的解释

<message id='923442621149' type='chat'><body>shanraisshan</body>
<reply xmlns='shayan:reply' rText='this is custom attribute'/>
</message>

其中回复是自定义扩展名,其中包含

where reply is a custom extension, which contains

  1. 元素(回复)
  2. 命名空间(shayan:回复)
  1. Element (reply)
  2. Namespace (shayan:reply)

默认的xmpp命名空间列表可在 XMPP官方网站

the list of default xmpp namespaces are available at Official XMPP website

这篇关于如何使用Smack库发送自定义XML数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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