Created
March 19, 2013 20:49
-
-
Save robhinds/5200010 to your computer and use it in GitHub Desktop.
SAX RSS Parser
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public void startElement(String uri, String localName, String qName, Attributes atts) { | |
chars = new StringBuffer(); | |
} | |
public void characters(char ch[], int start, int length) { | |
chars.append(new String(ch, start, length)); | |
} | |
public void endElement(String uri, String localName, String qName) throws SAXException { | |
if (localName.equalsIgnoreCase("title")){ | |
currentArticle.setTitle(chars.toString()); | |
} else if (localName.equalsIgnoreCase("description")){ | |
currentArticle.setDescription(chars.toString()); | |
} else if (localName.equalsIgnoreCase("published")){ | |
currentArticle.setPubDate(chars.toString()); | |
} else if (localName.equalsIgnoreCase("id")){ | |
currentArticle.setGuid(chars.toString()); | |
} else if (localName.equalsIgnoreCase("author")){ | |
currentArticle.setAuthor(chars.toString()); | |
} else if (localName.equalsIgnoreCase("content")){ | |
currentArticle.setEncodedContent(chars.toString()); | |
} else if (localName.equalsIgnoreCase("entry")){ | |
} | |
// Check if looking for article, and if article is complete | |
if (localName.equalsIgnoreCase("entry")) { | |
articleList.add(currentArticle); | |
currentArticle = new Article(); | |
// Lets check if we've hit our limit on number of articles | |
articlesAdded++; | |
if (articlesAdded >= ARTICLES_LIMIT){ | |
throw new SAXException(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment