SAXFeedHandler extends DefaultHandler implements FeedHandler { @Override public Feed processXml(String xmlData) throws HttpHelper.XmlDataException { InputStream reader = null; try { SAXParserFactory saxParserFactory = SAXParserFactory.newInstance(); saxParserFactory.setValidating(false); saxParserFactory.setNamespaceAware(true); SAXParser saxParser = saxParserFactory.newSAXParser(); reader = new ByteArrayInputStream(xmlData.getBytes("UTF-8")); saxParser.parse(reader, this); } catch (Exception e) { Timber.e(e, "Error in processXml"); throw new HttpHelper.XmlDataException(HttpHelper.XmlDataException.ERROR_PARSE); } finally { ResourceHelper.closeResource(reader); } return new Feed(channel, episodeList); } SAXFeedHandler(Channel channel); @Override Feed processXml(String xmlData); @Override void startElement(String uri, String localName, String qName, Attributes attributes); @Override void endElement(String uri, String localName, String qName); @Override void characters(char ch[], int start, int length);  }
@Test public void parseValidXml() throws Exception { String data = getTestData("atp_rss.xml"); SAXFeedHandler feedHandler = new SAXFeedHandler(new Channel()); Feed feed = feedHandler.processXml(data); Assert.assertNotNull(feed); Assert.assertEquals(100, feed.getEpisodeList().size()); Assert.assertEquals("Accidental Tech Podcast", feed.getChannel().getTitle()); Assert.assertEquals("Marco Arment, Casey Liss, John Siracusa", feed.getChannel().getAuthor()); Assert.assertEquals("Three nerds discussing tech, Apple, programming, and loosely related matters.", feed.getChannel().getDescription()); }