我正在使用 XStream,但我在使用特殊字符 á、é、í、ó、ú 和 ñ 时遇到问题。
我尝试过这个:
String charset = "UTF-8";
xstream = new XStream(new DomDriver(charset));
(不起作用)
我的问题是我不知道如何提供 Writer...
// get the model from the map passed created by the controller
Object model = map.get("model");
Object viewData = transformViewData(model);
//TEST
Writer w = new OutputStreamWriter(viewData, "UTF-8");
//FINTEST
// if the model is null, we have an exception
String xml = null;
if (viewData != null){
xml = xstream.toXML(viewData, w); //Err:Cannot find symbol...
}else{
// so render entire map
xml = xstream.toXML(map, w); //Err:Cannot find symbol...
}
response.getOutputStream().write(xml.getBytes());
最佳答案
这是 right there in the javadoc .
Writer w = new OutputStreamWriter(new FileOutputStream("test.xml"), "UTF-8");
XStream.toXML(object, w);
关于java - 带有特殊字符的 Xstream,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5250312/