0

I am doing a task based on retrieving images from the picasa public albums. It's returning response in the atom feed format. Here is the response snippet im getting from the picasa.

<item>
<guid isPermaLink="false">https://picasaweb.google.com/data/entry/base/user/112104498664640193446/albumid/5791036084570489841/photoid/5791036081578935442?alt=rss&amp;hl=en_US</guid>
<pubDate>Sat, 22 Sep 2012 16:17:38 +0000</pubDate>
<atom:updated>2012-09-24T19:11:05.625Z</atom:updated>
<category domain="http://schemas.google.com/g/2005#kind">http://schemas.google.com/photos/2007#photo</category>
<title>SACHIN-TENDULKAR-WALLPAPER-51[1].jpg</title>
<description>&lt;table>&lt;tr>&lt;td style="padding: 0 5px">&lt;a href="https://picasaweb.google.com/112104498664640193446/Sachin?authkey=Gv1sRgCMG2v_GY6-iiOg#5791036081578935442">&lt;img style="border:1px solid #5C7FB9" src="https://lh3.googleusercontent.com/-IQEQp8boLEg/UF3kokv7hJI/AAAAAAAAACk/cr53Fr8fUC4/s288/SACHIN-TENDULKAR-WALLPAPER-51%25255B1%25255D.jpg" alt="SACHIN-TENDULKAR-WALLPAPER-51[1].jpg"/>&lt;/a>&lt;/td>&lt;td valign="top">&lt;font color="#6B6B6B">Date: &lt;/font>&lt;font color="#333333">Sep 22, 2012 4:17 PM&lt;/font>&lt;br/>&lt;font color=\"#6B6B6B\">Number of Comments on Photo:&lt;/font>&lt;font color=\"#333333\">0&lt;/font>&lt;br/>&lt;p>&lt;a href="https://picasaweb.google.com/112104498664640193446/Sachin?authkey=Gv1sRgCMG2v_GY6-iiOg#5791036081578935442">&lt;font color="#3964C2">View Photo&lt;/font>&lt;/a>&lt;/p>&lt;/td>&lt;/tr>&lt;/table></description>
<enclosure type="image/jpeg" url="https://lh3.googleusercontent.com/-IQEQp8boLEg/UF3kokv7hJI/AAAAAAAAACk/cr53Fr8fUC4/SACHIN-TENDULKAR-WALLPAPER-51%25255B1%25255D.jpg" length="0"/>
<link>https://picasaweb.google.com/112104498664640193446/Sachin?authkey=Gv1sRgCMG2v_GY6-iiOg#5791036081578935442</link>
<media:group>
<media:content url="https://lh3.googleusercontent.com/-IQEQp8boLEg/UF3kokv7hJI/AAAAAAAAACk/cr53Fr8fUC4/SACHIN-TENDULKAR-WALLPAPER-51%25255B1%25255D.jpg" height="384" width="512" type="image/jpeg" medium="image"/>
<media:credit>NW_MAY08</media:credit>
<media:description type="plain"/>
<media:keywords/>
<media:thumbnail url="https://lh3.googleusercontent.com/-IQEQp8boLEg/UF3kokv7hJI/AAAAAAAAACk/cr53Fr8fUC4/s72/SACHIN-TENDULKAR-WALLPAPER-51%25255B1%25255D.jpg" height="54" width="72"/>
<media:thumbnail url="https://lh3.googleusercontent.com/-IQEQp8boLEg/UF3kokv7hJI/AAAAAAAAACk/cr53Fr8fUC4/s144/SACHIN-TENDULKAR-WALLPAPER-51%25255B1%25255D.jpg" height="108" width="144"/>
<media:thumbnail url="https://lh3.googleusercontent.com/-IQEQp8boLEg/UF3kokv7hJI/AAAAAAAAACk/cr53Fr8fUC4/s288/SACHIN-TENDULKAR-WALLPAPER-51%25255B1%25255D.jpg" height="216" width="288"/>
<media:title type="plain">SACHIN-TENDULKAR-WALLPAPER-51[1].jpg</media:title>
</media:group>
</item>

EDIT:

public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {
        //Only consider elements from allowed third-party namespaces
        if (NAMESPACES.contains(uri)) {
            mSb = new StringBuffer();
            String value = localName.trim();
            //Log.i(TAG, "start");
            if (value.equalsIgnoreCase("rss") ||  value.equalsIgnoreCase("rdf")) {
                isType = true;
            } else if (value.equalsIgnoreCase("feed")) {
                isType = true;
                isFeed = true;
            } else if (value.equalsIgnoreCase("channel")) {
                isFeed = true;
            } else if (value.equalsIgnoreCase("item") || value.equalsIgnoreCase("entry")) {
                mItem = new Item();
                imageLoader = new ImageLoader(context);
                isItem = true;      
            } else if (value.equalsIgnoreCase("title"))
                isTitle = true;
            else if (value.equalsIgnoreCase("link")) {
                // Get attributes from link element for Atom format
                if (attributes != null) {
                    // Enclosure for Atom format
                    if (attributes.getValue("rel") != null && attributes.getValue("rel").equalsIgnoreCase("enclosure")) {
                        mEnclosure = new Enclosure();
                        mMimeAttribute = attributes.getValue("type");
                        isEnclosure = true;
                    }
                    mHrefAttribute = attributes.getValue("href");
                }
                isLink = true;
            } else if (value.equalsIgnoreCase("pubDate") || value.equalsIgnoreCase("published") || value.equalsIgnoreCase("date"))
                isPubdate = true;
            else if (value.equalsIgnoreCase("guid") || value.equalsIgnoreCase("id"))
                isGuid = true;
            else if (value.equalsIgnoreCase("description") || value.equalsIgnoreCase("summary"))
                isDescription = true;
            else if (value.equalsIgnoreCase("encoded") || value.equalsIgnoreCase("content"))
                isContent = true;
            else if (value.equalsIgnoreCase("source"))
                isSource = true;
            else if(value.equalsIgnoreCase("media:group")){
                isMedia = true;
                Log.i("media", "media group");
            }
            else if (value.equalsIgnoreCase("enclosure")) {
                // Enclosure for RSS format
                if (attributes != null) {
                    mEnclosure = new Enclosure();
                    mMimeAttribute = attributes.getValue("type");
                    mHrefAttribute = attributes.getValue("url");
                    if(mMimeAttribute.equalsIgnoreCase("image/jpeg")){
                        mItem.setImageUrl(mHrefAttribute);
                    }
                    Bitmap bmp = imageLoader.getBitmap(mHrefAttribute);
                    mItem.setBitmapImage(bmp);
                    isEnclosure = true;
                }
            }else if(value.equalsIgnoreCase("media:content")){
                if(attributes != null){
                    mMediaContent = new MediaContent();
                    mMimeAttribute_media = attributes.getValue("type");
                    mHrefAttribute_media = attributes.getValue("url");
                }
            }
        }
    }

EDIT 2

Here is the logcat when i use Log.i("RSSHandler", "localName="+localName+", qName="+qName);

10-02 14:04:51.799: I/RSSHandler(3090): localName=item, qName=item
10-02 14:04:51.799: I/RSSHandler(3090): localName=guid, qName=guid
10-02 14:04:51.799: I/RSSHandler(3090): localName=pubDate, qName=pubDate
10-02 14:04:51.799: I/RSSHandler(3090): localName=updated, qName=atom:updated
10-02 14:04:51.799: I/RSSHandler(3090): localName=category, qName=category
10-02 14:04:51.799: I/RSSHandler(3090): localName=title, qName=title
10-02 14:04:51.799: I/RSSHandler(3090): localName=description, qName=description
10-02 14:04:51.819: I/RSSHandler(3090): localName=enclosure, qName=enclosure
10-02 14:04:51.839: I/RSSHandler(3090): localName=link, qName=link
10-02 14:04:51.839: I/RSSHandler(3090): localName=group, qName=media:group
10-02 14:04:51.839: I/RSSHandler(3090): localName=content, qName=media:content
10-02 14:04:51.839: I/RSSHandler(3090): localName=credit, qName=media:credit
10-02 14:04:51.839: I/RSSHandler(3090): localName=description, qName=media:description
10-02 14:04:51.839: I/RSSHandler(3090): localName=keywords, qName=media:keywords
10-02 14:04:51.839: I/RSSHandler(3090): localName=thumbnail, qName=media:thumbnail
10-02 14:04:51.839: I/RSSHandler(3090): localName=thumbnail, qName=media:thumbnail
10-02 14:04:51.839: I/RSSHandler(3090): localName=thumbnail, qName=media:thumbnail
10-02 14:04:51.839: I/RSSHandler(3090): localName=title, qName=media:title

i tried modifying the code like this:

else if(qName.trim().equalsIgnoreCase("media:content") || value.equalsIgnoreCase("content")){

                if (attributes != null) {
                    mMediaContent  = new MediaContent();
                    mHrefAttribute_media = attributes.getValue("url");
                    Log.i("media url", mHrefAttribute_media);
                }
                isMedia = true;
                Log.i("media group", "media content");
            }

But this is not working.

I am unable to read medai:group from this response. I tried this but im unable to get the result. can any one please help me in doing this. Thank you.

Dan Lowe
  • 51,713
  • 20
  • 123
  • 112
wolverine
  • 1,665
  • 5
  • 24
  • 43
  • How are you parsing it? Which parser did you use? In the tag `media:group`, `media` is the namespace and `group` is the element name. – Rajesh Oct 01 '12 at 10:15
  • @Rajesh I am using SAX Parser. See this link. Im using the same process. http://www.javaworld.com/javaworld/jw-02-2012/120214-jtip-rss-for-android.html?page=2 – wolverine Oct 01 '12 at 10:20
  • Please post the code snippet where you read the required element. – Rajesh Oct 01 '12 at 10:26

1 Answers1

0

The media:group contains two parts media, which is the namespace prefix and group, which is the element name.

The localName and qName parameters of startElement are explained in XML SAX: Explain result in `qName` and `localName` in one example XML file

So you can modify your code as follows:

        else if(qName.equalsIgnoreCase("media:group")){
            isMedia = true;
            Log.i("media", "media group");
        }
Community
  • 1
  • 1
Rajesh
  • 15,724
  • 7
  • 46
  • 95
  • Please check if you are having any exception in the LogCat. Try to add debug log statements and see what is being passed as parameters to the startElement. – Rajesh Oct 01 '12 at 13:53
  • Please check [Reading and Writing Logs](http://developer.android.com/tools/debugging/debugging-log.html) to see how you can write and use log statements. I am sorry, but I cannot chat on gtalk. – Rajesh Oct 01 '12 at 14:01
  • It's ok.. But i am able to see the log if i put Log.i("", "") in the other parts of the snippet – wolverine Oct 01 '12 at 14:04
  • Try adding `Log.i("RSSHandler", "localName="+localName+", qName="+qName);` at the beginning of the startElement method. – Rajesh Oct 02 '12 at 05:12
  • What does `NAMESPACES` contain? You may also try adding `uri` to the log statement. – Rajesh Oct 02 '12 at 09:42
  • here is namespace: private static final Set NAMESPACES = new HashSet(Arrays.asList(new String[] {"","http://purl.org/rss/1.0/modules/content/", "http://www.w3.org/2005/Atom","http://purl.org/rss/1.0/","http://purl.org/dc/elements/1.1/"})); – wolverine Oct 02 '12 at 09:58
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/17444/discussion-between-rajesh-and-wolverine) – Rajesh Oct 02 '12 at 10:40