问题
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