public boolean process() { boolean status = true; Application currentRecord = null; boolean inEntry = false; String textValue = ""; try { XmlPullParserFactory factory = XmlPullParserFactory.newInstance(); factory.setNamespaceAware(true); XmlPullParser xpp = factory.newPullParser(); xpp.setInput(new StringReader(this.xmlData)); int eventType = xpp.getEventType(); while (eventType != XmlPullParser.END_DOCUMENT) { String tagName = xpp.getName(); switch (eventType) { case XmlPullParser.START_TAG: // Log.d("ParseApplications", "Starting tag for " + tagName); if (tagName.equalsIgnoreCase("entry")) { inEntry = true; currentRecord = new Application(); } break; case XmlPullParser.TEXT: textValue = xpp.getText(); break; case XmlPullParser.END_TAG: // Log.d("ParseApplications", "Ending tag for " + tagName); if (inEntry) { if (tagName.equalsIgnoreCase("entry")) { applications.add(currentRecord); inEntry = false; } else if (tagName.equalsIgnoreCase("name")) { currentRecord.setName(textValue); } else if (tagName.equalsIgnoreCase("artist")) { currentRecord.setArtist(textValue); } else if (tagName.equalsIgnoreCase("releaseDate")) { currentRecord.setReleaseDate(textValue); } } break; default: // nothing else to do } eventType = xpp.next(); } } catch (Exception e) { status = false; e.printStackTrace(); } return true; }
public boolean process() { boolean operationStatus = true; Application currentRecord = null; boolean inEntry = false; String textValue = ""; try { XmlPullParserFactory factory = XmlPullParserFactory.newInstance(); factory.setNamespaceAware(true); XmlPullParser xpp = factory.newPullParser(); xpp.setInput(new StringReader(this.data)); int eventType = xpp.getEventType(); while (eventType != XmlPullParser.END_DOCUMENT) { String tagName = xpp.getName(); if (eventType == XmlPullParser.START_TAG) { if (tagName.equalsIgnoreCase("entry")) { inEntry = true; currentRecord = new Application(); } } else if (eventType == XmlPullParser.TEXT) { textValue = xpp.getText(); } else if (eventType == XmlPullParser.END_TAG) { if (inEntry) { if (tagName.equalsIgnoreCase("entry")) { apps.add(currentRecord); inEntry = false; } if (tagName.equalsIgnoreCase("name")) { currentRecord.setName(textValue); } else if (tagName.equalsIgnoreCase("artist")) { currentRecord.setArtist(textValue); } else if (tagName.equalsIgnoreCase("releaseDate")) { currentRecord.setReleaseDate(textValue); } } } eventType = xpp.next(); } } catch (Exception e) { e.printStackTrace(); operationStatus = false; } for (Application app : apps) { Log.d("LOG", "***********************"); Log.d("LOG", app.getName()); Log.d("LOG", app.getArtist()); Log.d("LOG", app.getReleaseDate()); } return operationStatus; }