Pubsub & Setting an element's xmlns

Hello,

Fairly new to the XMPP scene, currently playing around with the Smack library along with the su-smack pubsub libraries and I’ve run into a problem I can’t seem to figure out yet, and it seems like it should be something fairly obvious that I’m overlooking.

I’m trying to do some simple operations with pubsub, like create, view, edit, update, delete nodes. The problem I’m running into is being able to set the xmlns on a pubsub tag when attempting to delete a node. The delete isn’t working, but that’s another story, and I’m pretty sure I need to get this step working first before the delete operation is successful. Here’s an example Java code, followed by the generated XML:

XMPPConnection con = new XMPPConnection("localhost");
con.connect(); con.login("username","password");
con.addPacketListener(new PacketListener(){
     public void processPacket(Packet pack) {
          System.err.println("Recv : "+ pack.toXML());                     }
},null); PubSub.setDefaultXmlns("http://jabber.org/protocol/pubsub#owner");
PubSub pubsub = new PubSub();    pubsub.setTo("pubsub.myopenfireservername");
pubsub.setType(IQ.Type.SET); // Check if the xmlns was set correctly
System.out.println("xmlns: " + pubsub.getXmlns()); DeleteElement de = new DeleteElement("node");
pubsub.addChild(de); System.out.println("Send : " + pubsub.toXML());
con.sendPacket(pubsub);
Thread.sleep(5000);
con.disconnect();

The System.out for the xmlns prints what I would expect:

xmlns: http://jabber.org/protocol/pubsub#owner

However, the System.out for the pubsub message looks like this:

<iq id="J6nJW-4" to="pubsub.myopenfireservername" type="set">
     <pubsub xmlns="http://jabber.org/protocol/pubsub">
          <delete node="node"></delete>
     </pubsub>
</iq>

Now, my question is: Why is the xmlns on the pubsub tag not what I set it too?

Any guidance or suggestions here would awesome.

Looks like it might be a shortcoming of the su-smack library. PubSub.java has a constant namespace variable that it uses for every pubsub tag xmlns attribute, paying no attention to the default xmlns:

public String getChildElementXML() {
    return "<pubsub xmlns=\""+NS+"\">"+getChild().toXML()+"</pubsub>";
}

where

private static final String NS = "http://jabber.org/protocol/pubsub";

Time to use my own version of the su-smack library I guess. Does anyone have a version of the su-smack library that does already support this functionality? If so, where did you get it from? This seems pretty critical for basic pubsub operations and I’m surprised that this was the issue, because it’s obvious in the pubsub spec (XEP-0060) that the xmlns is important for certain node operations.

On a related note, is using the Packet.setDefaultXmlns(String xmlns) method the right way to set the xmlns for a packet? Being that it’s a static method which doesn’t really seem suited for more granular control of individual xmlns attributes of xmpp packets, I figure there must be a better way… I don’t understand why there isn’t a setXmlns(String xmlns) method on the Packet class. Could someone please explain?

I had exactly the same problem some months ago and got in contact with Leif from su-smack project. He stated that this will not be changed because of some compatibility issues with their own xmpp-server … and I also had to use my own su-smack version (with some other extensions).