This is with Smack 4.4.3.
As far as I can tell, when child elements of an IQ are called, their toXML
method is called with the enclosingXMLNamespace
of the IQ itself, i.e. jabber:client
, not the IQ of the IQ child element.
For example, from the following Java code (using only Smack classes):
Jingle.Builder jingleBuilder = Jingle.getBuilder();
jingleBuilder.setSessionId("MySession");
jingleBuilder.setAction(JingleAction.content_accept);
JingleContent.Builder jingleContentBuilder = JingleContent.getBuilder();
jingleContentBuilder.setName("Hello world");
jingleContentBuilder.setCreator(JingleContent.Creator.initiator);
jingleBuilder.addJingleContent(jingleContentBuilder.build());
Jingle iq = jingleBuilder.build();
CharSequence xml = iq.toXML();
generates the XML (formatting added):
<iq xmlns='jabber:client' id='EKP8I-1' type='set'>
<jingle xmlns='urn:xmpp:jingle:1' action='content-accept' sid='MySession'>
<content xmlns='urn:xmpp:jingle:1' creator='initiator' name='Hello world'>
</content>
</jingle>
</iq>
I.e. xmlns='urn:xmpp:jingle:1'
is repeated between the <jingle>
element and the <content>
element, because content
's toXML
is passed the wrong parent namespace, and so its encoder doesn’t suppress repeating it.
This causes redundant XML namespaces to be included on the wire; and in the unlikely event that a child element had the XML namespace jabber:client
, its namespace would be suppressed and the encoded XML would be actively wrong.
Is there a way around this for my own elements, and/or can it easily be fixed in Smack?