使用 SAX 方式,有些內文資訊會遺漏, 用 Pull XML OK
try {
URL url = new URL(RSS_URL);
HttpURLConnection conn = (HttpURLConnection)url.openConnection();
//conn.setRequestMethod("POST");
conn.setDoInput(true);
conn.setUseCaches(false);
conn.connect();
//
InputStream in = new BufferedInputStream(conn.getInputStream());
BufferedReader reader = new BufferedReader(new InputStreamReader(in));
final XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
final XmlPullParser parser = factory.newPullParser();
parser.setInput(reader);
for(int type = parser.getEventType(); type != XmlPullParser.END_DOCUMENT; type = parser.next()) {
switch (type) {
case XmlPullParser.START_TAG:
//String id = parser.getAttributeValue(0);
tagName = parser.getName();
if (tagName==null) { }
else if (tagName.equals("link")) { sFlag = true; }
else if (tagName.equals("title")) { sFlag = true; }
else if (tagName.equals("description")) { sFlag = true; }
else if (tagName.equals("pubDate")) { sFlag = true; }
break;
case XmlPullParser.END_TAG:
break;
case XmlPullParser.TEXT:
break;
}
}
reader.close();
} catch(Exception e) { }