I wanted to upgrade to the latest version of the smack library (4.0.3, currently using 3.2.1) but noticed that a bug was introduced in the new version that broke my regression tests. I use the pubsub mechanisms for machine-to-machine communication and exchange XML data using the PubSub mechanism. The XML naturally contains a lot of namespace declarations that are vital for parsing the content at the receiver (subscriber).
Previously, this worked fine, but the new version does something strange with the namespaces in the published item. Instead of passing the content of the item as it was published, the library seems to remove all but one namespace from my XML data. So the my ItemEventListener implementation gets items with invalid XML code which cannot further be processed.
Are there any workarounds to get the items as they were published out of the smack library?
Allright, I’ve created a commit with a supposed solution/workaround. The problem is that if we use XmlPullParser.getNamespace() on elements that don’t define a namespace, then the parser will report the namespace of the outer element (which is not wrong, just sometime not required).
For example
some text
will become
some text
Smack’s PubSub ItemProvider does now use this approach. I’ve uploaded new 4.0.4-SNAPSHOTS to Sonatype. Since your problem description leaves room for interpretation, I’m not sure if I tried to fix the issue you are talking about. Please let me know if the 4.0.4-SNAPSHOTS solve the issue for you. Logged as SMACK-601.
I wonder why the library does not provide the content of the item as-it-is.
Basically because the xml-roundtrip feature of XmlPullParser is not available on Android and Smack tries to stay Android compatible. xml-roundtrip makes getText() return the full tag text when the parser in on START_TAG and END_TAG. Whithout this feature, we can only create the payload by parsing every tag and inspecting its attributes and namespace declarations. This introduces the mentioned effects when parsing XML of unkown structure, which is done very rarely when it comes to XMPP, but PubSub PayloadItem is a noteable exception.
BTW Smack is modular, you can always easily replace ItemProvider by your own implementation. To create a SimplePayload class which payload equals the input.
As with the current implementation, the prefix is lost, but it seems that it’s ok for you.
Please open a new thread for a different problem and provide more details. The IQ stanza does look like a custom one. It doesn’t look similar, more like a faulty parser implementation. How is it parsed? How does the class look like?