I'm sending custom XML messages from server to clients. An Android is a client which should know how to handle custom XML messages. The problem with asmack (which I'm using for receiving/sending messages) is that it tries to parse the message itself. An example message of the playerlist is the following:
<html xmlns="http://jabber.org/protocol/xhtml-im">
<body xmlns="http://www.w3.org/1999/xhtml">
<players xmlns="boxer:players" command="playerlist">
<player>test1</player>
<player>test2</player>
</players>
</body>
</html>
In Android, I'm adding a custom Extenstion Provider with:
ProviderManager.getInstance().addExtensionProvider("html","http://jabber.org/protocol/xhtml-im", new XMLPlayerListProvider());
And the XMLPlayerListProvider
class XMLPlayerListProvider implements PacketExtensionProvider {
public XMLPlayerListProvider() {}
public PacketExtension parseExtension(XmlPullParser parser) {
Log.w("**********HHHHHHHHHHHHH***********", "0");
boolean stop = false;
int evtType;
String n;
String id = null;
Log.w("START: "+XmlPullParser.START_TAG, "0");
while (!stop) {
try {
evtType = parser.next();
n = parser.getName();
switch (evtType) {
case XmlPullParser.START_TAG:
if ("body".equals(n))
Log.w("BODY"+n.toString(), "0");
else if ("players".equals(n))
Log.w("PLAYERS", "0");
else if ("player".equals(n))
Log.w("PLAYER", "0");
break;
case XmlPullParser.END_TAG:
//Stop parsing when we hit </item>
stop = "body".equals(n);
break;
}
} catch(Exception e) {
e.printStackTrace();
}
}
return new XMLPlayerList();
}
}
class XMLPlayerList implements PacketExtension {
public String getElementName() {
return "aaaaa";
}
public String getNamespace() {
return "aaaaa";
}
public String toXML() {
return "aaaaa";
}
}
When debugging I'm getting the following output:
W/**********HHHHHHHHHHHHH***********( 654): 0
W/START: 2( 654): 0
W/BODYbody( 654): 0
D/SMACK ( 654): 11:11:58 PM RCV (1156379984): mand="playerlist">
D/SMACK ( 654): <player>test1</player>
D/SMACK ( 654): <player>test2</player>
D/SMACK ( 654): </players>
D/SMACK ( 654): </body></html><thread>8rOVz0</thread></message><iq
W/PLAYERS ( 654): 0
W/PLAYER ( 654): 0
W/PLAYER ( 654): 0
W/RESPONSE: <message id="15" to="eee@localhost" from="admin@localhost" type="chat"><body>
test1
test2
</body><thread>
Here we can see that something strange is going on, but the PacketExtension is indeed getting called. My question now is: how can I change the XMLPlayerListProvider to receive the basic XML message without it being parsed by the default Android packet extension, which I guess is what's outputed as:
test1
test2
That should be:
<players xmlns="boxer:players" command="playerlist">
<player>test1</player>
<player>test2</player>
</players>