2014-09-05 79 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提要。