他正在使用 sax 解析器,而不是列出我想要一次提取一条记录的所有内容。这是我从中提取的 xml
<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0">
<channel>
<title>Conservation Tips</title>
<link>blah</link>
<description>Living comfortably during a Memphis summer can be challenging, but it does not have to be costly. What are some of the easiest ways to stay cool and save?</description>
<item>
<title>Have a professional, reputable contractor clean and inspect your air conditioner. This should be done every year, whether you have window or central units.</title>
</item>
<item>
<title>Set the thermostat at 78 degrees or higher for the most energy efficient operation. Each degree below this setting adds 6% to your cooling costs.</title>
</item>
<item>
<title>Check your air conditioner's filter every time you receive your utility bill.</title>
</item>
<item>
<title>Use fans to move the air inside your home. This gives the sensation that it is 5 degrees cooler than the actual temperature.</title>
</item>
<item>
<title>Shade windows on the sunny side of your home.</title>
</item>
<item>
<title>Keep drapes closed or add room-darkening shades to block out the heat from the sun.</title>
</item>
<item>
<title>The outside portion of a central air conditioner is the condensing unit. Keep it clear from dried mud, debris and grass clippings, because it needs to breathe.</title>
</item>
<item>
<title>Use your programmable thermostat to automatically increase the temperature setting at bedtime.</title>
</item>
<item>
<title>Sleep under lightweight bedding and use fans during sleep.</title>
</item>
<item>
<title>Do not place lamps near your thermostat. The thermostat senses the heat produced from the lamp and causes the air conditioner to run longer than necessary.</title>
</item>
<item>
<title>Do not set your thermostat at a colder setting than normal when you turn on your air conditioner. It will not cool your home any faster and could result in excessive cooling and, therefore, unnecessary expense.</title>
</item>
</channel>
这是我的代码
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
try {
url = new URL("url");
} catch (MalformedURLException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
RssFeed feed = null;
try {
feed = RssReader.read(url);
} catch (SAXException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
ArrayList<RssItem> rssItems = feed.getRssItems();
for(RssItem rssItem : rssItems) {
Log.i("RSS Reader", rssItem.getTitle());
//Log.i(rssItem.getTitle(), rssItem.getDescription());
//Log.i("RSS Content", rssItem.getLink());
}
}}
我想做的是一次随机显示一个项目。我可以把它们都拉出来,但似乎不能一次得到一个。任何帮助表示赞赏。谢谢