我正在使用simpleFramework来解析我的安卓应用程序中的xml文件。我的问题是在解析法语文本时,比如下面的标签
<TagName>écrite</TagName> 我在解析时得到的结果类似于“simpleFramework xml编码(法语)问题”。怎样才能避免这种情况,让我的文本"écrite“
xml头文件有utf8:
<?xml version="1.0" encoding="UTF-8"?>发布于 2013-02-07 22:22:04
我以前在使用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文件的。
https://stackoverflow.com/questions/14749449
复制相似问题