i m 采用xmlpullparser in android to parse an xml document that look as:
<top>
<category>
<name></name>
<desc></desc>
<songs>
<song>
<clip></clip>
<thumb></thumb>
</song>
<song>
<clip></clip>
<thumb></thumb>
</song>
</songs>
</category>
</top>
我试图这样做:
while (eventType != XmlPullParser.END_DOCUMENT && !done){
String name = null;
switch (eventType){
case XmlPullParser.START_DOCUMENT:
categoriesSong = new ArrayList<TopMousika>();
break;
case XmlPullParser.START_TAG:
name = parser.getName();
if (name.equalsIgnoreCase(CATEGORY)){
currentCategory = new TopMousika();
currentCategory.setId(parser.getAttributeValue(0));
currentCategory.setId(parser.getAttributeValue(1));
} else if (currentCategory != null){
if (name.equalsIgnoreCase(NAME)){
currentCategory.setName(parser.nextText());
} else if (name.equalsIgnoreCase(DESCRIPTION)){
currentCategory.setDescription(parser.nextText());
} else if (name.equalsIgnoreCase(THUMBNAIL)){
currentCategory.setThumbnail(parser.nextText());
} else if (name.equalsIgnoreCase(SONGS)){
songs = new ArrayList<SongMousika>();
if(name.equalsIgnoreCase(SONG)){
currentSong = new SongMousika();
currentSong.setId(parser.getAttributeValue(0));
Log.d("TEST", "OK");
songs.add(currentSong);
} else if (name.equalsIgnoreCase(TITLE)){
Log.d("TEST", "OK2");
currentSong.setTitle(parser.nextText());
} else if (name.equalsIgnoreCase(SINGER)){
currentSong.setTitle(parser.nextText());
} else if (name.equalsIgnoreCase(THUMBNAIL)){
currentSong.setTitle(parser.nextText());
} else if (name.equalsIgnoreCase(PUBLICATION_DATE)){
currentSong.setTitle(parser.nextText());
} else if (name.equalsIgnoreCase(CLIP)){
currentSong.setTitle(parser.nextText());
}
currentCategory.setSongs(songs);
}
}
break;
case XmlPullParser.END_TAG:
name = parser.getName();
if (name.equalsIgnoreCase(CATEGORY) &&
currentCategory != null){
currentCategory.setSongs(songs);
categoriesSong.add(currentCategory);
} else if (name.equalsIgnoreCase(TOP)){
done = true;
}
break;
}
eventType = parser.next();
}
but I can not retrieve my Songs List.
can any one help me please ?