java - XMLPullParser android colon tags -
i have found several questions of name question, can't of them work. want url of media:thumbnail tag:
<media:thumbnail width="144" height="81" url="http://c.files.bbci.co.uk/6013/production/_88159542_3e6f2bc3-16a3-407d-9e07-62bae1fa755e.jpg"/> above example of such tag
private void handletext(string text) { string xmltext = text; if (currententry != null && currenttag != null) { if (currenttag.equals(title)) { currententry.settitle(xmltext); } else if (currenttag.equals(desc)) { currententry.setdescription(xmltext); } else if (currenttag.equals(link)) { currententry.setlink(xmltext); } else if (currenttag.equals(image)) { currententry.setimage("test"); } } } i tried several things as:
xpp.getattributevalue(null, "url"); , set image that. noticed not getting in else if clause. tried several values on image variable like:
- media:thumbnail
- media
- thumbnail
i have set namespace aware:
factory.setnamespaceaware(true); what doing wrong?
parser:
xmlpullparser xpp; int eventtype; protected list<entry> doinbackground(string... string) { try { xmlpullparserfactory factory = xmlpullparserfactory.newinstance(); factory.setnamespaceaware(true); xpp = factory.newpullparser(); xpp.setinput(getinputstream(new url("http://feeds.bbci.co.uk/news/technology/rss.xml?edition=uk")), "utf_8"); eventtype = xpp.geteventtype(); while (eventtype != xmlpullparser.end_document) { if (eventtype == xmlpullparser.start_tag) { handlestarttag(xpp.getname()); } else if (eventtype == xmlpullparser.end_tag) { currenttag = null; } else if (eventtype == xmlpullparser.text) { handletext(xpp.gettext()); } eventtype = xpp.next(); } } catch (resources.notfoundexception e) { log.d(logtag, e.getmessage()); } catch (xmlpullparserexception e) { log.d(logtag, e.getmessage()); } catch (ioexception e) { log.d(logtag, e.getmessage()); } return entries; }
i fixed it. systemed out start tags parsing , showed as: thumbnail. changed image constant have value of "thumbnail". never came in thumbnail clause since handletext method handles found text in tag. since media:thumbnail has no text attributes values needed handle in handlestarttag method. there if current tag name equals "thumbnail" attribute value of url , setimage value.
Comments
Post a Comment