1. Download the #1 Android News App:   EarlyBird - News for Android
    Dismiss Notice

GetAttribute value on android aml parser

Last Updated:

  1. krishnaveni

    krishnaveni Well-Known Member

    I have to develop one android application.

    Its performs the attribute value is display on listview...

    This is my xml tags:

    I have used below code:
    public class MainActivity extends Activity {

    String URL;
    static String KEY_CATEGORY = "Categories";
    ArrayList<HashMap<String, String>> songsList;
    static final String KEY_PNAME = "Category";
    static final String KEY_PRICE = "Description";
    static final String KEY_THUMB_URL = "thumb_image";

    ListAdapter adapter;

    /** Called when the activity is first created. */
    protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    songsList = new ArrayList<HashMap<String, String>>();
    HorizontalListView list = (HorizontalListView) findViewById(R.id.listView1);

    adapter = new ListAdapter(this, songsList);


    XMLParser parser = new XMLParser();
    String xml = parser.getXmlFromUrl(URL); // getting XML from URL
    Document doc = parser.getDomElement(xml);// getting DOM element

    NodeList nl = doc.getElementsByTagName(KEY_CATEGORY);

    // looping through all song nodes &lt;song&gt;
    for (int i = 0; i < nl.getLength(); i++) {
    // creating new HashMap
    HashMap<String, String> map = new HashMap<String, String>();
    Element e = (Element) nl.item(i);
    // adding each child node to HashMap key =&gt; value
    map.put( KEY_PNAME,((Element)nl.item(i)).getAttribute("name"));

    map.put(KEY_PRICE, parser.getValue(e, KEY_PRICE));
    map.put(KEY_THUMB_URL, parser.getValue(e, KEY_THUMB_URL));

    // adding HashList to ArrayList

    // Click event for single list row
    list.setOnItemClickListener(new OnItemClickListener() {

    public void onItemClick(AdapterView<?> parent, View view,
    int position, long id) {
    HashMap<String, String> map = songsList.get(position);

    Here i have to run the app means the category name is displayed on listview.How can i get the attribute value ??? please help me.

    I got the below error:


  2. krishnaveni

    krishnaveni Well-Known Member


    I got the o/p after change the below line:

    Now i have to run the app means am getting the attribute value well...

Share This Page