Redundant XML namespace in IQ child elements?

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?

It can. I have created SMACK-917 and opened

I think that is not the case. If there would be a direct child element of qualified by the jabber:client namespace, then supressing the namespace declartion would be valid. Or maybe I do not understand you.

I think that is not the case. If there would be a direct child element of qualified by the jabber:client namespace, then supressing the namespace declartion would be valid. Or maybe I do not understand you.

The worry would be if the IQ child had a namespace of (e.g.) urn:xmpp:jingle:1, but it had a subelement with the namespace jabber:client, the old code would suppress jabber:client, leading receivers to think the subelement had the namespace urn:xmpp:jingle:1.

Regardless, your PR fixes it.

1 Like

This topic was automatically closed 62 days after the last reply. New replies are no longer allowed.