multiple item xml parsin in android -


my xml this:

<?xml version="1.0" encoding="utf-8"?> <menu> <item>     <id>1</id>       <name>margherita</name>     <cost>         <p>155</p>         <p>255</p>         <p>355</p>         <p>455</p>     </cost>     <description>single cheese topping</description> </item>  <item>     <id>2</id>         <name>double cheese margherita</name>     <cost>         <p>900</p>         <p>155</p>     </cost>     <description>loaded cheese</description> </item>  <item>     <id>3</id>         <name>fresh veggie</name>     <cost>         <p>335</p>     </cost>     <description>oninon , crisp capsicum</description> </item>  

in cost tag have other tags i'm trying parsing xml this:

    xmlparser parser = new xmlparser();     string xml = parser.getxmlfromurl(url); // getting xml     document doc = parser.getdomelement(xml); // getting dom element      nodelist nl = doc.getelementsbytagname(key_item);     // looping through item nodes <item>     (int = 0; < nl.getlength(); i++) {         // creating new hashmap         hashmap<string, string> map = new hashmap<string, string>();         element e = (element) nl.item(i);         // adding each child node hashmap key => value         map.put(key_id, parser.getvalue(e, key_id));         map.put(key_name, parser.getvalue(e, key_name));         map.put(key_desc, parser.getvalue(e, key_desc));            // adding hashlist arraylist         menuitems.add(map);     } 

i want access child nodes, here , add loop access

values how access childern nodes ?!

your items stored in list, can element this:

hashmap item = menuitems.get(0); // first item 

or can loop through elements in list:

for (hashmap item: menuitems) {     // } 

now might wonder how access it's properties, can use hashmap this:

string name = item.get(key_name); 

Comments

Popular posts from this blog

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -