我正在尝试从 url link 获取 xml 文件。
此代码适用于安卓。
我正在使用 SAXParser 来完成此操作。
但我有错误:
org.apache.harmony.xml.ExpatParser$ParseException: At line 1, column 87: not well-formed (invalid token)
在这条线上
saxParser.parse(url.openStream(),handler);
我的代码是:
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);
可以做什么?
问题似乎是您尝试解析的 XML 不是 UTF-8,因此您需要告诉 SAX 使用哪种编码。
像这样的东西应该可以工作(虽然没有测试过)
InputSource is = new InputSource(url.openStream());
is.setEncoding("Cp1255");
parser.parse(is, handler);
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)