I am building an Android app that parses an RSS feed using SAX parser. When I print the title, I only get the first character of it.
public void characters(char ch[], int start, int length)
{
String theString = new String(ch,start,length);
//Log.i("RSSReader","characters[" + theString + "]");
switch (currentstate)
{
case RSS_TITLE:
_item.setTitle(theString);
Log.i("tag","Length:"+length);
currentstate = 0;
break;
}
}
Here, the log says that the length is 1 always. This even happens with the description. Before it was working with another feed, now its got trouble when I switched to another feed.
Here is example title tag:
<title>"The Color of the Night is not always Black II_(Explored Highest Position #1)" by xris74</title>
What I get printed on screen is " that is (quote)
Thanks in advance!
EDIT 1:
I added up string builder.
1. Added new string builder variable:
StringBuilder newString;
2. On Element Start, if its title
newString = new StringBuilder();
3. On Element End, if its title
_item.setTitle(newString.toString());
4. In characters function, if its title tag, than:
newString.append(ch,start,length);
The
characters()function can be called many times after the start tag and before the end tag. Each time it brings you some bytes but not necessarily all the bytes at once in one call.So you can create a
StringBuilderinonStartTagfunction. Then append to that StringBuilder every time you enter the characters function. Then when you enteronEndTagfunction for this tag your StringBuilder will have all the characters.What to append is determined by the
offsetandlengthparameters of thecharactersfunction