我使用這裡方法與SAXparser進行分析:URL url = new URL(urlToParse);
SAXParserFactory spf = SAXParserFactory.newInstance();
//here we get our SAX parser
SAXParser sp = spf.newSAXParser();
//we fuse it to a XML reader
XMLReader xr = sp.getXMLReader();
DefaultHandler handlerContact = new DefaultHandler();
//we give it a handler to manage the various events
xr.setContentHandler(handlerContact);
//and finally we open the stream to the url
InputStream oS = url.openStream();
//and parse it
xr.parse(new InputSource(new InputStreamReader(oS, Charset.forName("utf-8"))));
//to retrieve the list of contacts created by the handler
result = handlerContact.getEntries();
//don't forget to close the resource
oS.close();
我從來沒有遇到任何麻煩,只要你正在解析的初始文件被正確編碼為 UTF-8. 檢查是否為,因為當你使用電腦的默認配置時,默認值不是 UTF-8,但是ANSI或者 ISO-8859-1.