xmlpullparser - Android XML Pull Parser - After parsing self closing tag, tag's attribute can't be show -


i want parse tag's attribute xml self closing tag, site : http://api.yr.no/weatherapi/locationforecast/1.9/?lat=-6.1980042;lon=106.8243594

i using code :

main activity.java :

public static arraylist<datum> parse(string url) throws ioexception, xmlpullparserexception {         final arraylist<datum> results = new arraylist<datum>();      url input = new url(url);      xmlpullparserfactory factory = xmlpullparserfactory.newinstance();     factory.setnamespaceaware(true);     xmlpullparser xpp = factory.newpullparser();      xpp.setinput(input.openstream(), null);     int eventtype = xpp.geteventtype();     string currenttag = null;     string temperature = null;      while (eventtype != xmlpullparser.end_document) {         if (eventtype == xmlpullparser.start_tag) {             currenttag = xpp.getname();         } else if (eventtype == xmlpullparser.text) {             log.d("mainactivity", "masuk start tag" );             if ("temperature".equals(currenttag)) {                 temperature = xpp.getattributevalue(1);             }          } else if (eventtype == xmlpullparser.end_tag) {             if ("location".equals(xpp.getname())) {                 results.add(new datum(temperature));             }         }         eventtype = xpp.next();     }     return results; }  public static arraylist<datum> parse2(string url) throws ioexception, xmlpullparserexception {     final arraylist<datum> results = new arraylist<datum>();      url input = new url(url);      xmlpullparserfactory factory = xmlpullparserfactory.newinstance();     factory.setnamespaceaware(true);     xmlpullparser xpp = factory.newpullparser();      xpp.setinput(input.openstream(), null);     xpp.nexttag();     xpp.require(xmlpullparser.start_tag, null, "weatherdata");     while (xpp.nexttag() == xmlpullparser.start_tag) {          xpp.require(xmlpullparser.start_tag, null, "product");         while (xpp.nexttag() == xmlpullparser.start_tag) {              xpp.require(xmlpullparser.start_tag, null, "time");             while (xpp.nexttag() == xmlpullparser.start_tag) {                  xpp.require(xmlpullparser.start_tag, null, "location");                 xpp.nexttag();                 xpp.require(xmlpullparser.start_tag, null, "temperature");                 string temperature = xpp.getattributevalue(1);                 log.d("mainactivity", "getattrbutevalue : " + xpp.getattributevalue(1));                   xpp.nexttag();                 xpp.require(xmlpullparser.end_tag, null, "location");                 results.add(new datum(temperature));             }             xpp.require(xmlpullparser.end_tag, null, "time");         }         xpp.require(xmlpullparser.end_tag, null, "product");     }     xpp.require(xmlpullparser.end_tag, null, "weatherdata");      return results; }  protected class loadrecipestask2 extends asynctask<string, integer, arraylist<datum>> {      @override     protected void onpreexecute() {         mprogressdialog.show();                                                          // 1     }      @override     protected arraylist<datum> doinbackground(string... urls) {         arraylist<datum> datumlist = new arraylist<datum>();         (int = 0; < urls.length; i++) {                                          // 2             try {                 datumlist = parse(urls[i]);                 publishprogress((int) (((i+1) / (float) urls.length) * 100));            // 3             } catch (ioexception e) {                 e.printstacktrace();             } catch (xmlpullparserexception e) {                 e.printstacktrace();             }         }         return datumlist;     }      @override     protected void onprogressupdate(integer... values) {                                 // 4         mprogressdialog.setprogress(values[0]);                                          // 5     }      @override     protected void onpostexecute(arraylist<datum> result) {         mlistview.setadapter(new arrayadapter<datum>(mainactivity.this, r.layout.list_item, result));         mprogressdialog.dismiss();                                                       // 6     } } 

where datum class :

package nl.codestone.recipelist; public class datum {  string temperature;  public datum(string temperature) {     this.temperature = temperature;  }  public string gettemperature() {     return temperature; }  } 

i want temperature's value attribute, value appear : nl.codestone.recipelist.datum@11a4d5920

anybody can ?


Comments