我正在构建一个分析以色列新闻网站(希伯来语)的新闻应用程序,我一直在第1行第17列收到此错误消息"org.apache.harmony.xml.expatparser$parseexception not - well-formed (invalid token)“现在我知道问题出在rss feed中的编码...the编码是”Windows1255“,rss feed”“org.apache.harmony.xml.expatparser$parseexception-...the:http://www.ynet.co.il/Integration/StoryRss2.xml”我尝试过:
SAXParserFactory spf = SAXParserFactory.newInstance();
SAXParser sp = spf.newSAXParser();
RssHandler rh = new RssHandler();
input= new InputSource(new StringReader(feed));
input.setEncoding("Windows-1255");
sp.parse(input, rh);但它不能工作...请帮帮我!谢谢
发布于 2014-09-06 05:58:20
您是如何将提要读入字符串的?xml可能被打断了,因为在我的Linux机器(缺省情况下是UTF8字符集)和OracleJava8上,这似乎没有错误:
SAXParserFactory spf = SAXParserFactory.newInstance();
try {
SAXParser sp = spf.newSAXParser();
InputSource input = new InputSource(new URL("http://www.ynet.co.il/Integration/StoryRss2.xml").openStream());
sp.parse(input, new DefaultHandler() {
@Override
public void startElement(String uri, String localName, String qName,
Attributes attributes) throws SAXException {
System.out.print(qName + ": ");
}
@Override
public void characters(char[] ch, int start, int length) throws SAXException {
System.out.print(new String(ch, start, length));
}
});
} catch (Exception e) {
e.printStackTrace();
}"org.apache.harmony.xml.expatparser$parseexception"..你在使用Apache Harmony吗?这是一个过时的Java实现,如果可能,请尝试更新到更新的版本。我还建议使用Rome来阅读rss。
https://stackoverflow.com/questions/25684380
复制相似问题