Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8781909
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T20:25:49+00:00 2026-06-13T20:25:49+00:00

I’m trying to write a code that parse an xml code and write the

  • 0

I’m trying to write a code that parse an xml code and write the values of each node in a list view

I’m working with this XML

http://www.iqraa.com/rss/CustomizedServices.aspx?Service=TvGuide

I try to follow this tutorial

http://www.androidhive.info/2011/11/android-xml-parsing-tutorial

but nothing work

any help please 🙁

this is the code of xmlparser

public class XMLParser {

public XMLParser() {

}

/**
 * Getting XML from URL making HTTP request
 * 
 * @param url
 *            string
 * */
public String getXmlFromUrl(String url) {
    String xml = null;

    try {
        // defaultHttpClient
        DefaultHttpClient httpClient = new DefaultHttpClient();
        HttpPost httpPost = new HttpPost(url);
        HttpResponse httpResponse = httpClient.execute(httpPost);
        HttpEntity httpEntity = httpResponse.getEntity();
        xml = EntityUtils.toString(httpEntity);

    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    } catch (ClientProtocolException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
    // return XML
    return xml;
}

/**
 * Getting XML DOM element
 * 
 * @param XML
 *            string
 * */
public Document getDomElement(String xml) {
    Document doc = null;

    DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
    // dbf.setCoalescing(true);
    try {

        DocumentBuilder db = dbf.newDocumentBuilder();

        InputSource is = new InputSource();
        is.setCharacterStream(new StringReader(xml));

        doc = db.parse(is);

    } catch (ParserConfigurationException e) {
        Log.e("Error: ", e.getMessage());
        return null;
    } catch (SAXException e) {
        Log.e("Error: ", e.getMessage());
        return null;
    } catch (IOException e) {
        Log.e("Error: ", e.getMessage());
        return null;
    }

    return doc;
}

/**
 * Getting node value
 * 
 * @param elem
 *            element
 */
public final String getElementValue(Node elem) {
    Node child;
    if (elem != null) {
        if (elem.hasChildNodes()) {
            for (child = elem.getFirstChild(); child != null; child = child
                    .getNextSibling()) {
                if (child.getNodeType() == Node.TEXT_NODE) {
                    return child.getNodeValue();
                }
            }
        }
    }
    return "";
}

/**
 * Getting node value
 * 
 * @param Element
 *            node
 * @param key
 *            string
 * */
public String getValue(Element item, String str) {
    NodeList n = item.getElementsByTagName(str);
    return this.getElementValue(n.item(0));
}

}

and this is the code of the MainActivity

public class MainActivity extends ListActivity {

static final String URL = "http://iqraa.com/rss/CustomizedServices.aspx?Service=TvGuide";
// XML node keys
static final String KEY_PITEM = "ProgramItem"; // parent node

static final String KEY_PNAME = "ProgramName";
static final String KEY_LINK = "Link";
static final String KEY_STARTTIME = "StartTime";
static final String KEY_CHANNEL = "Channel";
static final String KEY_SCHEDULE = "ScheduleDate";
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    ArrayList<HashMap<String, String>> menuItems = new ArrayList<HashMap<String, String>>();

    XMLParser parser = new XMLParser();
    String xml = parser.getXmlFromUrl(URL); // getting XML

    Log.i("Inside 1  Oncreate", "On create done");
    Document doc = parser.getDomElement(xml); // getting DOM element

    NodeList nl = doc.getElementsByTagName(KEY_PITEM);

    // looping through all item nodes <item>
    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 => value
        map.put(KEY_PNAME, parser.getValue(e, KEY_PNAME));
        //map.put(KEY_LINK, parser.getValue(e, KEY_LINK));
        Log.i("Inside 1  Oncreate", "FOR LOOOOOOP ");
        map.put(KEY_STARTTIME,parser.getValue(e, KEY_STARTTIME));
        map.put(KEY_CHANNEL,parser.getValue(e, KEY_CHANNEL));
        map.put(KEY_SCHEDULE, parser.getValue(e, KEY_SCHEDULE));

        // adding HashList to ArrayList
        menuItems.add(map);
    }


    // Adding menuItems to ListView
    ListAdapter adapter = new SimpleAdapter(this, menuItems,
            R.layout.list_item,
            new String[] { KEY_PNAME, KEY_STARTTIME, KEY_CHANNEL}, new int[] {
                    R.id.name, R.id.stime, R.id.channel });
    Log.i("Inside 3  Oncreate", "2222222");

    setListAdapter(adapter);

    // selecting single ListView item
    ListView lv = getListView();

    lv.setOnItemClickListener(new OnItemClickListener() {

        public void onItemClick(AdapterView<?> parent, View view,
                int position, long id) {
            // getting values from selected ListItem
            Log.i("Inside 1  Oncreate", "44444444");
            String name = ((TextView) view.findViewById(R.id.name)).getText().toString();
            String channel = ((TextView) view.findViewById(R.id.channel)).getText().toString();
            String stime = ((TextView) view.findViewById(R.id.stime)).getText().toString();

            // Starting new intent
            Intent in = new Intent(getApplicationContext(), SingleMenuItemActivity.class);
            in.putExtra(KEY_PNAME, name);
            in.putExtra(KEY_CHANNEL, channel);
            in.putExtra(KEY_STARTTIME, stime);
            startActivity(in);

        }
    });


}

}

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T20:25:51+00:00Added an answer on June 13, 2026 at 8:25 pm
    you have to add permissions for this parsing xml in manifest.
    
    add this line in Manifest file
     <uses-permission android:name="android.permission.INTERNET"/>
    
    See your activity class here Now it is working  fine.Run this Example in Device,for  Emulator check permissions may be there are any restrictions.
    
    package com.rmn.xmlparser;
    
    import java.util.ArrayList;
    import java.util.HashMap;
    
    import org.w3c.dom.Document;
    import org.w3c.dom.Element;
    import org.w3c.dom.NodeList;
    
    import android.app.Activity;
    import android.content.Intent;
    import android.os.Bundle;
    import android.util.Log;
    import android.view.View;
    import android.widget.AdapterView;
    import android.widget.AdapterView.OnItemClickListener;
    import android.widget.ListAdapter;
    import android.widget.ListView;
    import android.widget.SimpleAdapter;
    import android.widget.TextView;
    
    public class ListxmlActivity extends Activity {
        static final String URL = "http://iqraa.com/rss/CustomizedServices.aspx?Service=TvGuide";
        // XML node keys
        static final String KEY_PITEM = "ProgramItem"; // parent node
    
        static final String KEY_PNAME = "ProgramName";
        static final String KEY_LINK = "Link";
        static final String KEY_STARTTIME = "StartTime";
        static final String KEY_CHANNEL = "Channel";
        static final String KEY_SCHEDULE = "ScheduleDate";
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.main);
            ArrayList<HashMap<String, String>> menuItems = new ArrayList<HashMap<String, String>>();
            // selecting single ListView item
            ListView lv =(ListView) findViewById(R.id.list);
    
            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_PITEM);
    
            // looping through all item nodes <item>
            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 => value
                map.put(KEY_PNAME, parser.getValue(e, KEY_PNAME));
                map.put(KEY_STARTTIME,parser.getValue(e, KEY_STARTTIME));
                map.put(KEY_CHANNEL,parser.getValue(e, KEY_CHANNEL));
                map.put(KEY_SCHEDULE, parser.getValue(e, KEY_SCHEDULE));
    
                // adding HashList to ArrayList
                menuItems.add(map);
            }
    
    
            // Adding menuItems to ListView
            ListAdapter adapter = new SimpleAdapter(this, menuItems,
                    R.layout.list_item,
                    new String[] { KEY_PNAME, KEY_STARTTIME, KEY_CHANNEL}, new int[] {
                            R.id.name, R.id.stime, R.id.channel });
            Log.i("Inside 3  Oncreate", "2222222");
    
            lv.setAdapter(adapter);
    
    
    
            lv.setOnItemClickListener(new OnItemClickListener() {
    
                public void onItemClick(AdapterView<?> parent, View view,
                        int position, long id) {
                    // getting values from selected ListItem
                    Log.i("Inside 1  Oncreate", "44444444");
                    String name = ((TextView) view.findViewById(R.id.name)).getText().toString();
                    String channel = ((TextView) view.findViewById(R.id.channel)).getText().toString();
                    String stime = ((TextView) view.findViewById(R.id.stime)).getText().toString();
    
                    // Starting new intent
                    Intent in = new Intent(getApplicationContext(), SingleMenuItemActivity.class);
                    in.putExtra(KEY_PNAME, name);
                    in.putExtra(KEY_CHANNEL, channel);
                    in.putExtra(KEY_STARTTIME, stime);
                    startActivity(in);
    
                }
            });
    
    
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
Basically, what I'm trying to create is a page of div tags, each has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have a French site that I want to parse, but am running into
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I know there's a lot of other questions out there that deal with this
I'm trying to create an if statement in PHP that prevents a single post
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.