Trouble parsing some RSS feeds using Java and Sax
Posted
by brockoli
on Stack Overflow
See other posts from Stack Overflow
or by brockoli
Published on 2010-05-29T05:28:03Z
Indexed on
2010/05/29
5:32 UTC
Read the original article
Hit count: 515
I've written an RSS feed parser in Java (running on Android) and it parses some feeds perfectly, and others not at all. I get the following error when it tries to parse Slashdot (http://rss.slashdot.org/Slashdot/slashdot)
org.apache.harmony.xml.ExpatParser$ParseException: At line 1, column 0: unbound prefix
If I try to parse Wired (http://feeds.wired.com/wired/index)
org.apache.harmony.xml.ExpatParser$ParseException: At line 1, column 0: syntax error
If I try to parse AndroidGuys (http://feeds.feedburner.com/androidguyscom)
org.apache.harmony.xml.ExpatParser$ParseException: At line 1, column 0: syntax error
Here is some code for my parser.
public void updateArticles(Context ctx, Feed feed, int numDaysToGet) {
try {
targetFlag = TARGET_ARTICLES;
tweetDB = new TweetMonsterDBAdapter(ctx);
tweetDB.open();
currentFeed = feed;
TimeZone.setDefault(TimeZone.getTimeZone("UTC")); // or "Etc/GMT-1"
Date currentDate = new Date();
long dateInMillis = currentDate.getTime();
oldestDate.setTime(dateInMillis-(dayInMillis*numDaysToGet));
SAXParserFactory spf = SAXParserFactory.newInstance();
SAXParser sp = spf.newSAXParser();
XMLReader xr = sp.getXMLReader();
xr.setContentHandler(this);
xr.parse(new InputSource(currentFeed.url.openStream()));
} catch (IOException e) {
Log.e("TweetMonster", e.toString());
} catch (SAXException e) {
tweetDB.close();
Log.e("TweetMonster", e.toString());
} catch (ParserConfigurationException e) {
Log.e("TweetMonster", e.toString());
}
tweetDB.close();
}
It doesn't even get into my startElement method.
© Stack Overflow or respective owner