java - Item doesn't store in ArrayList with different XML structure -
currently i'm doing exercise on processing xml , storing arraylist, work when i'm using this xml. when switch this xml, data not stored in arraylist. have done output testing , seems data did not pass here feeditems.add(new feeditem(title,date));
. hope can explain me going on code , how can fix issue.
mainactivity.java
new readrss(mainactivity.this, listview, "http://www.thestar.com.my/rss/editors-choice/main/").execute();
readrss.java
public void parsexmlandstoreit(xmlpullparser myparser) { int event; string text; string title = null; string date = null; feeditems = new arraylist<feeditem>(); try { event = myparser.geteventtype(); while (event != xmlpullparser.end_document) { string tagname = myparser.getname(); switch (event){ case xmlpullparser.start_tag: if(tagname.equalsignorecase("item")){ int eventchild = myparser.next(); //int innerloop = 1; string tagnamechild = ""; while(eventchild != xmlpullparser.end_document){ if(eventchild == xmlpullparser.start_tag){ tagnamechild = myparser.getname(); // output test //log.d("tag ", tagnamechild); } else if (eventchild == xmlpullparser.text){ text = myparser.gettext(); // output test //log.d("test ", text); if(tagnamechild.equalsignorecase("title")){ title = text; // output test //log.d("title ", myparser.gettext()); } else if(tagnamechild.equalsignorecase("pubdate")){ date = text; // output test //log.d("pubdate ", myparser.gettext()); } } else if (eventchild == xmlpullparser.end_tag){ if(myparser.getname().equalsignorecase("item")){ feeditems.add(new feeditem(title,date)); // output test //log.d("test ", title); } } eventchild = myparser.next(); //innerloop++; } //output test for(int = 0; < feeditems.size(); i++) { log.d("title", feeditems.get(i).gettitle()); log.d("date", feeditems.get(i).getpubdate()); } } break; case xmlpullparser.text: break; case xmlpullparser.end_tag: break; } event = myparser.next(); } parsingcomplete = false; } catch (exception e) { e.printstacktrace(); } }
feeditem.java
public class feeditem { string title; string link; string description; string pubdate; string thumbnailurl; public feeditem (string title, string pubdate){ this.title = title; this.pubdate = pubdate; } public string gettitle() { return title; } public string getlink() { return link; } public void setlink(string link) { this.link = link; } public string getdescription() { return description; } public void setdescription(string description) { this.description = description; } public string getpubdate() { return pubdate; } public void setpubdate(string pubdate) { this.pubdate = pubdate; } public string getthumbnailurl() { return thumbnailurl; } public void setthumbnailurl(string thumbnailurl) { this.thumbnailurl = thumbnailurl; } }
i don't know did wrong, because copied parser code , feeditem , parsed both xmls!
- xml - 50 feeditems
- xml - 10 feeditems
however parsing not ok, because titles , dates overwritten empty text, cleared
after every endtag tagnamechild
variable. after got feeditems correct title , date!
code fix:
else if (eventchild == xmlpullparser.end_tag) { if (myparser.getname().equalsignorecase("item")) { feeditems.add(new feeditem(title, date)); // output test //log.d("test ", title); } tagnamechild = ""; }
Comments
Post a Comment