I am currently parsing Xml bye Dom but i want to get the elements and the attributes of them i don't know how i get it , i can not get the elements name and values and attributes of each element also can help me please.
   private void parsexml(String xmlresult){        ListView myList=(ListView)findViewById(android.R.id.list);        menuItems = new ArrayList<HashMap<String, String>>();        XmlParser parser = new XmlParser();      Document doc = parser.getDomElement(xmlresult); // getting DOM element      NodeList nl = doc.getElementsByTagName("*");            // looping through all item nodes <item>      for (int i = 0; i < nl.getLength(); i++) {            Node nNode = nl.item(i);          if (nNode.getNodeType() == Node.ELEMENT_NODE) {                Element e = (Element) nl.item(i);                Element eElement = (Element) nNode;              String tagname = eElement.getTagName();              // creating new HashMap              HashMap<String, String> map = new HashMap<String, String>();                // adding each child node to HashMap key => value              map.put(KEY_ID, parser.getValue(e, KEY_ID));              map.put(KEY_NAME, parser.getValue(e, KEY_NAME));              map.put(KEY_COST, "Rs." + parser.getValue(e, KEY_COST));              map.put(KEY_DESC, parser.getValue(e, KEY_DESC));              map.put(KEY_categroy, parser.getValue(e, KEY_categroy));              map.put(KEY_order, parser.getValue(e, KEY_order));              // adding HashList to ArrayList              menuItems.add(map);          }      }      // Adding menuItems to ListView      ListAdapter adapter = new SimpleAdapter(this, menuItems,              R.layout.list_item,              new String[] { KEY_NAME, KEY_DESC, KEY_COST,KEY_categroy,KEY_order }, new int[] {              R.id.name, R.id.desciption, R.id.cost,R.id.categroy,R.id.order });        setListAdapter(adapter);      ((BaseAdapter)adapter).notifyDataSetChanged();  }      xml
  <Roomtype IDRoom="1" Code="A1D" NormBed="1" Maxbed="2" Category="3" Order="4"><Description Name="Deluxe Double Room" Text="" IDLanguage="4"/>     
No comments:
Post a Comment