我正在执行一项基于从 picasa 公共相册中检索图像的任务。它以原子提要格式返回响应。这是我从 picasa 获得的响应片段。
<item>
<guid isPermaLink="false">https://picasaweb.google.com/data/entry/base/user/112104498664640193446/albumid/5791036084570489841/photoid/5791036081578935442?alt=rss&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><table><tr><td style="padding: 0 5px"><a href="https://picasaweb.google.com/112104498664640193446/Sachin?authkey=Gv1sRgCMG2v_GY6-iiOg#5791036081578935442"><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"/></a></td><td valign="top"><font color="#6B6B6B">Date: </font><font color="#333333">Sep 22, 2012 4:17 PM</font><br/><font color=\"#6B6B6B\">Number of Comments on Photo:</font><font color=\"#333333\">0</font><br/><p><a href="https://picasaweb.google.com/112104498664640193446/Sachin?authkey=Gv1sRgCMG2v_GY6-iiOg#5791036081578935442"><font color="#3964C2">View Photo</font></a></p></td></tr></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>
编辑:
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");
}
}
}
}
编辑 2
这是我使用 Log.i("RSSHandler", "localName="+localName+", qName="+qName); 时的 logcat
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
我尝试像这样修改代码:
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");
}
但这不起作用。
我无法从此回复中阅读 medai:group。我试过这个,但我无法得到结果。谁能帮我做这件事。谢谢你。