Maybe it is possible to write an adapter for a XmlPullParser, i.e. a class which implements XMLStreamReader and gets an XmlPullParser in its constructor and then delegates the calls to the XmlPullParser.
I am sorry, but I don’t understand this approach nor the advantages.
I was thinking about an adapter class like this. Granted, there is no big advantage. But I’d feel more comfortable working with a “standard” (javax.xml) interface than wrapping both worlds into a third (Smack) interface. But that’s only my opinion.
For Android create an instance of XmlPullParserAdapter passing Androids XmlPullParser. For Java SE just use XmlInputFactory.newFactory().createXmlStreamReader().
Then work with XMLStreamReader.
public class XmlPullParserAdapter implements XMLStreamReader {
private final XmlPullParser xmlPullParser;
public XmlPullParserAdapter(XmlPullParser xmlPullParser) {
this.xmlPullParser = xmlPullParser;
}
@Override
public Object getProperty(String name) throws IllegalArgumentException {
return xmlPullParser.getProperty(name);
}
@Override
public int next() throws XMLStreamException {
try {
return xmlPullParser.next();
} catch (XmlPullParserException | IOException e) {
throw new XMLStreamException(e);
}
}
@Override
public void require(int type, String namespaceURI, String localName) throws XMLStreamException {
try {
xmlPullParser.require(type, namespaceURI, localName);
} catch (XmlPullParserException | IOException e) {
throw new XMLStreamException(e);
}
}
…
And if you provide your own (Smack) interface for Android or if you make javax.xml interface available there by including a “light” interface jar, should be no big difference.