xml - Parse two elements with same name android -


i'm bit new xml , android development... i've encountered issue need parse xml elements same , include overall element. it's bit hard explain, see code below:

<tns:camera>  <tns:congestionlocations> <tns:congestion>free flow</tns:congestion> <tns:direction>eastbound</tns:direction> </tns:congestionlocations>  <tns:congestionlocations> <tns:congestion>free flow</tns:congestion> <tns:direction>westbound</tns:direction> </tns:congestionlocations>   <tns:description>bond st looking east</tns:description> <tns:direction>eastbound</tns:direction> <tns:group>sh16-north-western</tns:group> <tns:lat>-36.869</tns:lat> <tns:lon>174.746</tns:lon> <tns:name>sh16 1 bond st</tns:name> <tns:viewurl>http://www.trafficnz.info/camera/view/130</tns:viewurl> </tns:camera> 

basically, need parse overall element (tns:camera) , include congestion locations (seperated each other obviously), within same class using of them in listview...

how achieve this?

at present, using pull parser, , parsing class object

pullparser code:

case xmlpullparser.end_tag:                     if (tagname.equalsignorecase(key_site)) {current site                         camerasites.add(curcameraclass);                     } else if (tagname.equalsignorecase(key_description)) {                          curcameraclass.setdescription(curtext);                     }else if (tagname.equalsignorecase(key_name)) {                         curcameraclass.setname(curtext);                     }                      break; 

kind regards!

try this..

        nodelist nodelist = doc.getelementsbytagname("tns:camera");                  (int = 0; < nodelist.getlength(); i++) {                      node node = nodelist.item(i);                             element fstelmnt = (element) node;                     nodelist namelist = fstelmnt.getelementsbytagname("tns:group");                     element nameelement = (element) namelist.item(0);                     namelist = nameelement.getchildnodes();                      system.out.println("tns:group : "+((node) namelist.item(0)).getnodevalue());                       element fstelmnt1 = (element) node;                     nodelist namelist1 = fstelmnt1.getelementsbytagname("tns:viewurl");                     element nameelement1 = (element) namelist1.item(0);                     namelist1 = nameelement1.getchildnodes();                      system.out.println("tns:viewurl : "+ ((node) namelist1.item(0)).getnodevalue());  //same use tns:description,tns:direction , tns:lat etc.,                       if(node.getnodetype() == node.element_node)                     {                         element e = (element) node;                         nodelist resultnodelist = e.getelementsbytagname("tns:congestionlocations");                         int resultnodelistsize = resultnodelist.getlength();                         for(int j = 0 ; j < resultnodelistsize ; j++ )                         {                             node resultnode = resultnodelist.item(j);                             if(resultnode.getnodetype() == node.element_node)                             {                                 element fstelmnt2 = (element) resultnode;                                 nodelist namelist2 = fstelmnt2.getelementsbytagname("tns:congestion");                                 element nameelement2 = (element) namelist2.item(0);                                 namelist2 = nameelement2.getchildnodes();                                  log.v("tns:congestion", ""+((node) namelist2.item(0)).getnodevalue());                                  element fstelmnt3 = (element) resultnode;                                 nodelist namelist3 = fstelmnt3.getelementsbytagname("tns:direction");                                 element nameelement3 = (element) namelist3.item(0);                                 namelist3 = nameelement3.getchildnodes();                                  log.v("tns:direction--", ""+((node) namelist3.item(0)).getnodevalue());                             }                         }                     }                  } 

Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -