in Android, Android Code Tips, Programming

SAXParser in Android, not returning full string

Never, NEVER trust the SAXParser in Android that it will return the full parsed string.

SAXParser may use the “characters” method of DefaultHandler twice if the string is long, BUT BE CAREFUL!

I noticed that SAXParser may use the characters method twice, even if the string is not long enough!

Solution:
Instead of using String fields, use the StringBuffer class and append the new text:

	private StringBuffer title = new StringBuffer();
	public String getTitle() {
		return title.toString();
	}
	public void setTitle(String title) {
		this.title.append(title);
	}
Share