getting the value from an attribute of an element in an rss xml feed

by LuKeNuKuM » Fri, 04 Sep 2009 01:53:03 GMT

Sponsored Links
 i folks,

i've been struggling to find a way to read in a url value from within
a tag in an xml feed. im so close but i just can't seem to crack it.

i started out using this
as a guide which works great but customising it to read in an
attribute of an element is causing me problems.

the feed is here:

within the xml's 'item' element is <media:thumbnail width="X"
height="X" url="X"/> it's the url attribute im after. i can get the
title back fine but the structure of the media:thumbnail tag means im
missing something!

what's interesting(!?) is the fact that when i remove the loop and
only go for the first item, i get the image back! the line with strImg
= imgElement.getAttribute("url") just won't work within the loop...
any ideas are greatly appreciated.

this is very rough n ready, im learning :-)


package apps.httpDownload;

import java.util.ArrayList;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;

import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.SAXException;
import android.os.Bundle;

import android.widget.ImageView;
import android.widget.TextView;

public class httpDownload extends Activity {
/** Called when the activity is first created. */
public void onCreate(Bundle savedInstanceState) {

ArrayList<String> dataReturned = DownloadRSS("http://");

TextView txt = (TextView) findViewById(;
for (int i = 0; i < dataReturned.size(); i++) {
if (i < 10)
txt.setText(txt.getText() + "\n" + dataReturned.get(i) +

Bitmap bitmap =
ImageView img = (ImageView) findViewById(;



private InputStream OpenHttpConnection(String urlString)
throws IOException
InputStream in = null;
int response = -1;

URL url = new URL(urlString);
URLConnection conn = url.openConnection();

if (!(conn instanceof HttpURLConnection))
throw new IOException("Not an HTTP connection");

HttpURLConnection httpConn = (HttpURLConnection) conn;

response = httpConn.getResponseCode();
if (response == HttpURLConnection.HTTP_OK) {
in = httpConn.getInputStream();
catch (Exception ex)

Other Threads

1. bypassing e-mail at startup

When you first get the phone, is there any way to bypass the part that
forces you to enter an e-mail address?  I'd like to just mess with the
phone a little before registering with my e-mail.


2. Updating a map intent

I have a basic Google Maps app within which I'd like to show some
dynamically generated KML from a server. So I use an intent and a Uri
like this:
                 Intent mapIntent = new Intent(Intent.ACTION_VIEW);
                 Uri uri = Uri.parse("geo:0,0?q=
                 startActivity(Intent.createChooser(mapIntent, "Sample

And it works fine. But what I would like to do is to poll the server
at regular intervals to get the latest data. How do I go about
"refreshing" activity so it reconnects to the server?

I've created a thread that periodically calls the code above, but it
only updates the first time.



3. TableRow

4. Update UI

5. Anyone from South Florida?

6. Program Dependant XML Values

7. Taking control of UI