Parsing French text with simple-Framework not working

六月ゝ 毕业季﹏ 提交于 2019-12-11 15:36:33

问题


I'm using simpleFramework for parsing an xml file in my android app. My problem is in parsing french text like lets say this tag

<TagName>écrite</TagName> 

The result I will receive when parsing is something like this "écrite" This is encoding (french) problem in the simpleFramework xml. How can avoid that and have my text "écrite"

the xml header has utf8 :

<?xml version="1.0" encoding="UTF-8"?>

回答1:


I have hit this issue before whilst using a SAX parser. When reading the file with a Java InputStream you need to specify the encoding of the stream in code- perhaps by reading the first line of the file as you have shown. Here is the code for assigning the encoding;

SAXParserFactory saxParserFactory = SAXParserFactory.newInstance();     
final SAXParser saxParser = saxParserFactory.newSAXParser();
// Note the encoding on the reader...
final Reader reader = new InputStreamReader(<your file stream>, "UTF-8");       
final InputSource inputSource = new InputSource(reader);        
inputSource.setEncoding("UTF-8");
saxParser.parse(inputSource, <some handler>);

Hope that helps. If not- post back with how you are reading the XML file.



来源:https://stackoverflow.com/questions/14749449/parsing-french-text-with-simple-framework-not-working

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!