i have xml string which i need to format and capture the data.
I tried a way but it gives me the following exception :
org.xmlpull.v1.XmlPullParserException: Unexpected token (position:TEXT {"data":"\u003c?...@1:538 in java.io.InputStreamReader@2af1e959)
at org.kxml2.io.KXmlParser.next(KXmlParser.java:432)
Method used for parsing is :
public void parseXml(String aadharResponse) throws XmlPullParserException {
try {
XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
factory.setNamespaceAware(true);
XmlPullParser xpp = factory.newPullParser();
InputStream inputStream = new ByteArrayInputStream(aadharResponse.getBytes(Charset.forName("UTF-8")));
xpp.setInput(inputStream,"UTF-8"); // pass input whatever xml you have
int eventType = xpp.getEventType();
while (eventType != XmlPullParser.END_DOCUMENT) {
if (eventType == XmlPullParser.START_DOCUMENT) {
Util.printMessage(TAG, "Start document");
} else if (eventType == XmlPullParser.START_TAG) {
Util.printMessage(TAG, "Start tag " + xpp.getName());
} else if (eventType == XmlPullParser.END_TAG) {
Util.printMessage(TAG, "End tag " + xpp.getName());
} else if (eventType == XmlPullParser.TEXT) {
Util.printMessage(TAG, "Text " + xpp.getText()); // here you get the text from xml
}
eventType = xpp.next();
}
Util.printMessage(TAG, "End document");
} catch (XmlPullParserException | IOException e) {
e.printStackTrace();
}
}
Can anyone suggest what's wrong in this?