Thursday, 5 September 2013

Android - SaxParser error: ParseException: At line 1, column 0: not well-formed (invalid token)

Android - SaxParser error: ParseException: At line 1, column 0: not
well-formed (invalid token)

I'm having the following exception when trying to parse some XML:
org.apache.harmony.xml.ExpatParser$ParseException: At line 1, column 0:
not well-formed (invalid token)
The main issue is that this has only happened in Android 2.2 or 2.3
devices, but the weirdest thing is that the first time I parse the
response it is ok, but all the following tries give me the parsing
exception.
My code is as follows:
URL url = new URL("http://m.ideasmusik.com/rss/?ct=mx");
SAXParserFactory spf = SAXParserFactory.newInstance();
SAXParser sp = spf.newSAXParser();
InputSource is = new
InputSource("http://m.ideasmusik.com/rss/?ct=mx");
is.setEncoding(HTTP.UTF_8);
// Parse content
MusicRSSParser parser = new MusicHandler.MusicRSSParser();
//DefaultHandler
XMLReader xr = sp.getXMLReader();
xr.setContentHandler(parser);
InputSource in = new InputSource(url.openStream());
in.setEncoding(HTTP.UTF_8);
xr.parse(in);
The XML is UTF-8 (I've read that is a common problem to have incorrect
encoding).
Any guess on what is going wrong? I thought that it could be something
with my handler but it crashes before my logic applies, right after the
startDocument() method.

No comments:

Post a Comment