Reputation: 8934
I am trying to get xml file from url link . This code for android. I am using SAXParser for doing it. but I have error:
org.apache.harmony.xml.ExpatParser$ParseException: At line 1, column 87: not well-formed (invalid token)
on this line
saxParser.parse(url.openStream(),handler);
my code is:
URL url = null;
try {
url = new URL("toryRss1854.xml");
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
SAXParserFactory factory = SAXParserFactory.newInstance();
SAXParser saxParser = null;
try {
saxParser = factory.newSAXParser();
saxParser.parse(url.openStream(),handler);
What can be done?
Upvotes: 5
Views: 2880
Reputation: 10043
The problem would appear to be that the XML you are trying to parsing is not UTF-8 so you need to tell SAX which encoding to use.
something like this should work (although not tested this)
InputSource is = new InputSource(url.openStream());
is.setEncoding("Cp1255");
parser.parse(is, handler);
Upvotes: 3