I am using the Xml Pull Parser to parse some Xml from a URL. I'm retrieving the values of the nodes without any problem, however I can't seem to get the node name - it's just returning null.
For example:
<ArtistName>Joe</ArtistName>
I can retrieve "Joe" but can't get what node "Joe" is from, so instead of returning "ArtistName", it returns null.
Here is my code:
public static void getAllXML(String url) throws
XmlPullParserException, IOException, URISyntaxException{
Log.i("*****PARSER CALLED******","****PARSER CALLED*****");
XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
factory.setNamespaceAware(true);
XmlPullParser parser = factory.newPullParser();
String tagName = parser.getName();
parser.setInput(new InputStreamReader(getUrlData(url)));
XmlUtils.beginDocument(parser,"EventsPricePoints");
int eventType = parser.getEventType();
do{
XmlUtils.nextElement(parser);
parser.next();
String nodeName = parser.getName();
eventType = parser.getEventType();
if(eventType == XmlPullParser.TEXT){
Log.i("************PARSER**********",nodeName+"....."+parser.getText());
}
} while (eventType != XmlPullParser.END_DOCUMENT) ;
}
As you can see, i'm trying to get the node name by using
parser.getName()
which is returning null. What am I doing wrong?