android - Parse xml from url. Exception -


i need info url("http://someurl.com/file.xml"). info in tags - "name", "surname".

how can ?

i know must using asynctask internet connection.

i trying using xmlpullparser in asynctask, exception "indeoutofbound"

class requesttask extends asynctask<string, void, void> {         string name;          @override         protected inputstream doinbackground(string... uri) {                 try {                     xmlpullparserfactory factory = xmlpullparserfactory.newinstance();                     factory.setnamespaceaware(true);                     xmlpullparser xpp = factory.newpullparser();                     xpp.setinput(new inputstreamreader(                             geturldata("http://someurl.com/file.xml")));                      while (xpp.geteventtype() != xmlpullparser.end_document) {                         if (xpp.geteventtype() == xmlpullparser.start_tag) {                             if (xpp.getname().equals("name")) {                                 name=xpp.getattributevalue(0);                             }                         }                         xpp.next();                     }                 } catch (throwable t) {                 }  } catch (ioexception e) {         //handle problems..         }         return null;         }  @override protected void onpostexecute(void result) {         super.onpostexecute(result);          toast.maketext(getactivity().getapplicationcontext(),         "name="+name, toast.length_short).show();          } 

}

look @ xml in "file.xml".

i suspect error here:

 ...  if (xpp.geteventtype() == xmlpullparser.start_tag) {    if (xpp.getname().equals("name")) {      name=xpp.getattributevalue(0);  // <- your"<name>" tag have attributes??? 

here tutorials on android xml processing:

in particular, note use of gettext() fetch element content.


Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -