使用简单框架解析法语文本不起作用

时间:2013-02-07 10:57:38

标签: android character-encoding xml-parsing xml-serialization simple-framework

我正在使用simpleFramework来解析我的Android应用程序中的xml文件。 我的问题在于解析法语文本,比如说这个标签

<TagName>écrite</TagName> 

解析时我将收到的结果是“écrite” 这是simpleFramework xml中的编码(法语)问题。 如何避免这种情况并让我的文字“écrite”

xml标头有utf8:

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

1 个答案:

答案 0 :(得分:3)

我在使用SAX解析器之前遇到过这个问题。使用Java InputStream读取文件时,您需要在代码中指定流的编码 - 也许通过读取文件的第一行,如您所示。以下是分配编码的代码;

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

希望有所帮助。如果没有 - 回复你如何阅读XML文件。