I am using ASMACK library fo my application. I received the following IQ from my server.
<iq id='bind_2' type='result'><bind xmlns='urn:ietf:params:xml:ns:xmpp-bind'><jid username='xx' fullname='yy'>xx@aa.bb.cc.dd/Resource</jid></bind></iq>
For parsing this IQ, I added the IQProvider while setting XmppConnection configuration by using ProviderManager class as
ProviderManager.getInstance().addIQProvider("bind",
"urn:ietf:params:xml:ns:xmpp-bind",
new CustomIQProvider());
And my CustomIQProvider class is
public class CustomIQProvider implements IQProvider {
public static final String NAME_SPACE = "urn:ietf:params:xml:ns:xmpp-bind";
@Override
public IQ parseIQ(XmlPullParser parser) throws Exception {
Log.i("My_TAG", "inside LivBindIQ");
CustomIQ bindIQ = new CustomIQ();
if (parser.getEventType() != XmlPullParser.START_TAG) {
throw new IllegalStateException(
"Parser not in proper position, or bad XML.");
}
boolean done = false;
while (!done) {
int eventType = parser.next();
if ((eventType == XmlPullParser.START_TAG)
&& ("entry".equals(parser.getName()))) {
eventType = parser.next();
String name = parser.nextText();
eventType = parser.next();
String value = parser.nextText();
}
else if (eventType == XmlPullParser.END_TAG) {
done = true;
}
}
return bindIQ;
}
}
And my CustomIQ class is,
public class CustomIQ extends IQ {
@Override
public String getChildElementXML() {
// TODO Auto-generated method stub
return null;
}
}
Now I am confused about, how the CustomIQProvider
class be executed.. I didn't get any log from CustomIQProvider
class. Whether my steps are correct otherwise I need to do any steps for calling my CustomIQProvider
class
Maybe there's a provider already register for this namespace? Perhaps you need to do the complete and correct parse of the XML on your IQProvider, and also your CustomIQ need to implement the correct output of the xml. You are checking for a tag, where clearly it doesn't exist, so this parser will never work. Assuming this is the tag you want to parse
I didn't tested but this should work, your parseIQ method should look like this
And your CustomIQ class: