c# - Xmlpullparser in Xamarin android -
i'm trying parse rss feed 1 website got stuck parsing images. want replace placeholders images website , when try nothing happens placeholders ar still there , here code feedservice class:
try { webrequest webrequest = webrequest.create(url); webresponse webresponse = webrequest.getresponse(); stream stream = webresponse.getresponsestream(); xmldocument xmldocument = new xmldocument(); xmldocument.load(stream); xmlnamespacemanager nsmgr = new xmlnamespacemanager(xmldocument.nametable); nsmgr.addnamespace("dc", xmldocument.documentelement.getnamespaceofprefix("dc")); nsmgr.addnamespace("content", xmldocument.documentelement.getnamespaceofprefix("content")); xmlnodelist itemnodes = xmldocument.selectnodes("rss/channel/item"); (int = 0; < itemnodes.count; i++) { feeditem feeditem = new feeditem(); if (itemnodes[i].selectsinglenode("title") != null) { feeditem.title = itemnodes[i].selectsinglenode("title").innertext; } if (itemnodes[i].selectsinglenode("image") != null) { feeditem.title = itemnodes[i].selectsinglenode("image").innertext; } if (itemnodes[i].selectsinglenode("link") != null) { feeditem.link = itemnodes[i].selectsinglenode("link").innertext; } if (itemnodes[i].selectsinglenode("pubdate") != null) { feeditem.pubdate = convert.todatetime(itemnodes[i].selectsinglenode("pubdate").innertext); } if (itemnodes[i].selectsinglenode("dc:creator", nsmgr) != null) { feeditem.creator = itemnodes[i].selectsinglenode("dc:creator", nsmgr).innertext; } if (itemnodes[i].selectsinglenode("category") != null) { feeditem.category = itemnodes[i].selectsinglenode("category").innertext; } if (itemnodes[i].selectsinglenode("description") != null) { feeditem.description = itemnodes[i].selectsinglenode("description").innertext; } if (itemnodes[i].selectsinglenode("content:encoded", nsmgr) != null) { feeditem.content = itemnodes[i].selectsinglenode("content:encoded", nsmgr).innertext; } else { feeditem.content = feeditem.description; } feeditemslist.add(feeditem); } } catch (exception) { throw; } return feeditemslist; } } }
and code feeditemlistadapter class tried replace placeholders images website:
public override view getview(int position, view convertview, viewgroup parent) { var feeditem = this.feedslist[position]; var view = (convertview ?? context.layoutinflater.inflate(resource.layout.feeditemlistitemlayout, parent, false)) linearlayout; view.findviewbyid<textview>(resource.id.title).text = feeditem.title.length < 51 ? feeditem.title : feeditem.title.substring(0, 50) + "..."; view.findviewbyid<textview>(resource.id.creator).text = feeditem.creator; view.findviewbyid<textview>(resource.id.pubdate).text = feeditem.pubdate.tostring("dd/mm/yyyy hh:mm"); imageview imageview = view.findviewbyid<imageview>(resource.id.placeholder); koush.urlimageviewhelper.seturldrawable (imageview, feeditem.image, resource.drawable.placeholder); return view; } } }
and this how looks after run it!
can help?
that's because have small error in code parse rss image node:
feeditem.title = itemnodes[i].selectsinglenode("image").innertext;
it should image not title property set:
feeditem.image = itemnodes[i].selectsinglenode("image").innertext;
Comments
Post a Comment