我正在尝试从包含阿拉伯字符的编码 XML 解析文件中获取DOM
元素。下面的方法采用解析的 xml 字符串,应该返回文档。UTF-8
这是xml的链接:
http://212.12.165.44:7201/UniNews121.xml
public Document getDomElement(String xml){
Document doc = null;
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
try {
DocumentBuilder db = dbf.newDocumentBuilder();
InputSource is = new InputSource();
StringReader xmlstring=new StringReader(xml);
is.setCharacterStream(xmlstring);
is.setEncoding("UTF-8");
//APP CRASHES HERE
doc = db.parse(is);
} catch (ParserConfigurationException e) {
Log.e("Error: ", e.getMessage());
return null;
} catch (SAXException e) {
Log.e("Error: ", e.getMessage());
return null;
} catch (IOException e) {
Log.e("Error: ", e.getMessage());
return null;
}
// return DOM
return doc;
}
错误:
09-18 13:36:20.031: E/Error:(3846): Unexpected token (position:TEXT xml version="1.0...@2:1 in java.io.InputStreamReader@4144ac08)
感谢您的帮助,但请在您的回答中具体说明