0

I have My Rss File Items :

<item >
<title>Prasad</title>
<link>http://www.tele.com/rssHostDescr.php?hostId=15</link>
<guid isPermaLink="false">http://www.tele.com/rssHostDescr.php?hostId=14</guid>
<pubDate>2013-04-10</pubDate>
<description>Prasad</description>
<media:thumbnail width='66' height='49' url='http://www.tele.com/hos/Panthi-image.jpg'></media:thumbnail>
</item>
<item>
........................
</item>

etc.....................

I'm trying to parse the above file,I'm able to get all the information(title,link,date)but my requirement is to get url attribute value. How do I get the URL value from media:thumbnail tag? Could any one help?

Here's my code:

public class AndroidXMLParsingActivity extends ListActivity {

    // All static variables
    static final String URL = "http://www.tele.com/RSSFeed/toriHos.php";
    // XML node keys
    static final String KEY_ITEM = "item"; // parent node
    static final String KEY_TITLE=  "title";

    static final String KEY_LINK = "link";
    static final String KEY_PUBDATE = "pubDate";
    static final String KEY_MEDIA = "media:thumbnail";

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        ArrayList<HashMap<String, String>> menuItems = new ArrayList<HashMap<String, String>>();

        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);
        NodeList n=doc.getElementsByTagName(KEY_MEDIA);

        // 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_TITLE, parser.getValue(e, KEY_TITLE));
            map.put(KEY_LINK, parser.getValue(e, KEY_LINK));
            map.put(KEY_PUBDATE, parser.getValue(e, KEY_PUBDATE));
            map.put(KEY_MEDIA, parser.getValue(e, KEY_MEDIA));//Here I'm not getting any value

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

Note:map.put(KEY_MEDIA, parser.getValue(e, KEY_MEDIA));//Here I'm not getting any value

1 Answer 1

1
Element e = (Element) nl.item(i);
String urlStr = e.getAttribute("url");

Hope this will help you.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.