サンプル XML
<feed xmlns="http://www.w3.org/2005/Atom">
<title>NDTV News - Top Stories</title>
<link>http://www.ndtv.com/</link>
<description>Latest entries</description>
<language>en</language>
<pubDate>Wed, 31 Jul 2013 22:33:00 GMT</pubDate>
<lastBuildDate>Wed, 31 Jul 2013 22:33:00 GMT</lastBuildDate>
<entry>
<title>Narendra Modi to be BJP's PM candidate, announcement before crucial assembly polls: sources</title>
<link>http://feedproxy.google.com/~r/NdtvNews-TopStories/~3/XN7dMIDe5YI/story01.htm</link>
<published>Wed, 31 Jul 2013 13:58:31 GMT</published>
<author>
<name>user42715</name>
</author>
<content type="html"><![CDATA[<div align="center"><a href="http://www.ndtv.com/news/images/topstory_thumbnail/ Shatrughan_Sinha_agency_120.jpg"><img border="0" src="http://www.ndtv.com/news/images/topstory_thumbnail/Shatrughan_Sinha_agency_120.jpg" alt="2013-07-29-08-43-05" /></a></div><p><span style="font-size: large;">The BJP is likely to anoint Narendra Modi as its prime ministerial candidate for the 2014 elections and make a formal announcement to that effect by September.</span><br /><br /><span style="font-size: large;"> The BJP is likely to anoint Narendra Modi as its prime ministerial candidate for the 2014 elections and make a formal announcement to that effect by September. </span><br /><br /><span style="font-size: large;">The BJP is likely to anoint Narendra Modi as its prime ministerial candidate for the 2014 elections and make a formal announcement to that effect by September. </span><br /><br /></p>]]></content>
</entry>
</feed>
以下のコードを使用して、タグ内の値と値を取得できました。
XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
private XmlPullParser parser = factory.newPullParser();
private InputStream urlStream = downloadUrl(urlString);
parser.setInput(urlStream, null);
int eventType = parser.getEventType();
boolean done = false;
while (eventType != XmlPullParser.END_DOCUMENT && !done) {
tagName = parser.getName();
switch (eventType) {
case XmlPullParser.START_DOCUMENT:
break;
case XmlPullParser.START_TAG:
if (tagName.equals("entry")) {
}
if (tagName.equals("title")) {
title = parser.nextText().toString();
Log.i(TITLE, title);
}
if (tagName.equals("published")) {
pubDate = parser.nextText().toString();
Log.i(PUBLISHEDDATE, pubDate);
}
if (tagName.equals("author")) {
readAuthor(parser);
Log.i(AUTHOR, author);
}
break;
case XmlPullParser.END_TAG:
if (tagName.equals("feed")) {
done = true;
} else if (tagName.equals("entry")) {
rssFeed = new RssFeedStructure(title);
rssFeedList.add(rssFeed);
}
break;
}
eventType = parser.next();
}
private String readAuthor(XmlPullParser parser) throws IOException,
XmlPullParserException {
parser.nextTag();
parser.require(XmlPullParser.START_TAG, null, "name");
author = parser.nextText().toString();
parser.require(XmlPullParser.END_TAG, null, "name");
return author;
}
タグから、テキスト値 (BJP はナレンドラ モディに油を注ぐ可能性が高い .....) 内の「href」値を取得するにはどうすればよいですか?
鬼ごっこ。