diff --git a/library/src/com/shirwa/simplistic_rss/RssHandler.java b/library/src/com/shirwa/simplistic_rss/RssHandler.java index 179bb00..21a0da2 100644 --- a/library/src/com/shirwa/simplistic_rss/RssHandler.java +++ b/library/src/com/shirwa/simplistic_rss/RssHandler.java @@ -1,6 +1,5 @@ package com.shirwa.simplistic_rss; - import org.xml.sax.Attributes; import org.xml.sax.SAXException; import org.xml.sax.helpers.DefaultHandler; @@ -31,7 +30,8 @@ public class RssHandler extends DefaultHandler { private boolean parsingTitle; private boolean parsingLink; private boolean parsingDescription; - + + private String tmpValue=""; public RssHandler() { //Initializes a new ArrayList that will hold all the generated RSS items. rssItemList = new ArrayList(); @@ -45,6 +45,7 @@ public List getRssItemList() { //Called when an opening tag is reached, such as or @Override public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException { + tmpValue = ""; if (qName.equals("item")) currentItem = new RssItem(); else if (qName.equals("title")) @@ -52,7 +53,7 @@ else if (qName.equals("title")) else if (qName.equals("link")) parsingLink = true; else if (qName.equals("description")) - parsingDescription = true; + parsingDescription=true; else if (qName.equals("media:thumbnail") || qName.equals("media:content") || qName.equals("image")) { if (attributes.getValue("url") != null) currentItem.setImageUrl(attributes.getValue("url")); @@ -62,6 +63,17 @@ else if (qName.equals("media:thumbnail") || qName.equals("media:content") || qNa //Called when a closing tag is reached, such as </item> or @Override public void endElement(String uri, String localName, String qName) throws SAXException { + if (currentItem != null) { + //If parsingTitle is true, then that means we are inside a tag so the text is the title of an item. + if (parsingTitle) + currentItem.setTitle(tmpValue); + //If parsingLink is true, then that means we are inside a <link> tag so the text is the link of an item. + else if (parsingLink) + currentItem.setLink(tmpValue); + //If parsingDescription is true, then that means we are inside a <description> tag so the text is the description of an item. + else if (parsingDescription) + currentItem.setDescription(tmpValue); + } if (qName.equals("item")) { //End of an item so add the currentItem to the list of items. rssItemList.add(currentItem); @@ -71,23 +83,15 @@ public void endElement(String uri, String localName, String qName) throws SAXExc else if (qName.equals("link")) parsingLink = false; else if (qName.equals("description")) - parsingDescription = false; + parsingDescription=false; + + } //Goes through character by character when parsing whats inside of a tag. @Override public void characters(char[] ch, int start, int length) throws SAXException { - if (currentItem != null) { - //If parsingTitle is true, then that means we are inside a <title> tag so the text is the title of an item. - if (parsingTitle) - currentItem.setTitle(new String(ch, start, length)); - //If parsingLink is true, then that means we are inside a <link> tag so the text is the link of an item. - else if (parsingLink) - currentItem.setLink(new String(ch, start, length)); - //If parsingDescription is true, then that means we are inside a <description> tag so the text is the description of an item. - else if (parsingDescription) - currentItem.setDescription(new String(ch, start, length)); - } + tmpValue += new String(ch, start, length); } }