1
我的Android RSS閱讀器有點問題。我使用XML解析器從RSS訂閱源獲取標籤,但有時在描述中,我有很多 - 例如<description> <img src="some random url"><table...
,e.t.c.我想處理它們,尤其是IMG標記。我可以如何處理所有這些(因爲我在描述中有一堆未解析的代碼)。這裏是我的解析器類中的一個讀取函數。描述中的過程標籤,Android,RSS,XML解析器
private List<RssItem> readFeed(XmlPullParser parser) throws XmlPullParserException, IOException {
parser.require(XmlPullParser.START_TAG, null, "rss");
String title = null;
String link = null;
String description = null;
String pubDate = null;
String url = null;
List<RssItem> items = new ArrayList<RssItem>();
while (parser.next() != XmlPullParser.END_DOCUMENT) {
if (parser.getEventType() != XmlPullParser.START_TAG) {
continue;
}
String name = parser.getName();
if (name.equals("title")) {
title = readTitle(parser);
} else if (name.equals("link")) {
link = readLink(parser);
}
else if(name.equals("description")) {
description = readDescription(parser);
}
else if(name.equals("pubDate")) {
pubDate = readPubDate(parser);
}
if (title != null && link != null) {
RssItem item = new RssItem(title, link, description, pubDate, url);
items.add(item);
title = null;
link = null;
description = null;
pubDate = null;
url = null;
}
}
return items;
}
private String readDescription(XmlPullParser parser) throws XmlPullParserException, IOException{
parser.require(XmlPullParser.START_TAG, ns, "description");
String description = readText(parser);
parser.require(XmlPullParser.END_TAG, ns, "description");
return description;
}
private String readText(XmlPullParser parser) throws IOException, XmlPullParserException {
String result = "";
if (parser.next() == XmlPullParser.TEXT) {
result = parser.getText();
parser.nextTag();
}
return result;
}
預先感謝您的回答