2014-09-05 55 views
1

即时建立一个新闻应用程序,解析以色列的新闻网站(希伯来语),我不断收到此错误“org.apache.harmony.xml.expatparser $ parseexception在第1列第17 (无效的令牌)“ 现在我知道问题出在编码... RSS源中的编码是”Windows-1255“, rss feed”view-source:http://www.ynet.co.il/Integration/StoryRss2.xml“ 我试过了:解析从一个希伯来新闻网站的Rss饲料

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); 

但它不工作.... 请帮助我! 谢谢

回答

0

你是如何阅读字符串的饲料?该XML可能打破了那里,因为这似乎与甲骨文的Java 8我的Linux机器上没有任何错误(默认字符集UTF8)工作:

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提要。