I would guess that xpp.getClass()
returns null when xpp
references the text inside a set of tags. If you look at the example in XmlPullParser's documentation:
while (eventType != XmlPullParser.END_DOCUMENT) { if(eventType == XmlPullParser.START_DOCUMENT) { System.out.println("Start document"); } else if(eventType == XmlPullParser.START_TAG) { System.out.println("Start tag "+xpp.getName()); } else if(eventType == XmlPullParser.END_TAG) { System.out.println("End tag "+xpp.getName()); } else if(eventType == XmlPullParser.TEXT) { System.out.println("Text "+xpp.getText()); } eventType = xpp.next(); }
Notice that the focus is on the eventType
. If you only want to grab "title"
and "link"
tags, add these checks inside the section for START_TAG
:
else if(eventType == XmlPullParser.START_TAG) { if(xpp.getName().equalsIgnoreCase("title")){ //Get title }else if(xpp.getName().equalsIgnoreCase("link")){ //Get link }}