DOM4J 生成中文XML出现乱码
2011-04-26 15:39
351 查看
1 使用FileWriter写中文xml出现乱码 很怪异。
XMLWriter writer=null;
try{
Document doc=DocumentHelper.parseText(result);
OutputFormat format=OutputFormat.createPrettyPrint();
format.setEncoding("UTF-8");
//FileOutputStream fos=new FileOutputStream(new File("C:\\GeoSearchResponse.xml"));
writer=new XMLWriter(new FileWriter(new File("C:\\GeoSearchResponse.xml")),format);
//writer=new XMLWriter(fos,format);
writer.write(doc);
System.out.println("xml:"+doc.asXML());
}catch(DocumentException w){
w.printStackTrace();
}catch(IOException i){
i.printStackTrace();
}finally{
if(writer!=null){
try{
writer.close();
}catch(IOException e){
e.printStackTrace();
};
};
};
2 经过反复测试和实验 改成FileOutputStream来写 结果良好
XMLWriter writer=null;
try{
Document doc=DocumentHelper.parseText(result);
OutputFormat format=OutputFormat.createPrettyPrint();
format.setEncoding("UTF-8");
FileOutputStream fos=new FileOutputStream(new File("C:\\GeoSearchResponse.xml"));
//writer=new XMLWriter(new FileWriter(new File("C:\\GeoSearchResponse.xml")),format);
writer=new XMLWriter(fos,format);
writer.write(doc);
System.out.println("xml:"+doc.asXML());
}catch(DocumentException w){
w.printStackTrace();
}catch(IOException i){
i.printStackTrace();
}finally{
if(writer!=null){
try{
writer.close();
}catch(IOException e){
e.printStackTrace();
};
};
};
XMLWriter writer=null;
try{
Document doc=DocumentHelper.parseText(result);
OutputFormat format=OutputFormat.createPrettyPrint();
format.setEncoding("UTF-8");
//FileOutputStream fos=new FileOutputStream(new File("C:\\GeoSearchResponse.xml"));
writer=new XMLWriter(new FileWriter(new File("C:\\GeoSearchResponse.xml")),format);
//writer=new XMLWriter(fos,format);
writer.write(doc);
System.out.println("xml:"+doc.asXML());
}catch(DocumentException w){
w.printStackTrace();
}catch(IOException i){
i.printStackTrace();
}finally{
if(writer!=null){
try{
writer.close();
}catch(IOException e){
e.printStackTrace();
};
};
};
2 经过反复测试和实验 改成FileOutputStream来写 结果良好
XMLWriter writer=null;
try{
Document doc=DocumentHelper.parseText(result);
OutputFormat format=OutputFormat.createPrettyPrint();
format.setEncoding("UTF-8");
FileOutputStream fos=new FileOutputStream(new File("C:\\GeoSearchResponse.xml"));
//writer=new XMLWriter(new FileWriter(new File("C:\\GeoSearchResponse.xml")),format);
writer=new XMLWriter(fos,format);
writer.write(doc);
System.out.println("xml:"+doc.asXML());
}catch(DocumentException w){
w.printStackTrace();
}catch(IOException i){
i.printStackTrace();
}finally{
if(writer!=null){
try{
writer.close();
}catch(IOException e){
e.printStackTrace();
};
};
};
相关文章推荐
- dom4j生成xml文件,解析后出现中文乱码问题
- dom4j解析utf-8 的xml出现中文乱码的为
- 关于dom4j中使用FileWriter构造XMLWriter导致生成的xml中文乱码总结。
- mysql反向生成hbm.xml后,由hibernate向sql写数据中文出现乱码问题
- win7 64位系统使用VS2010生成时出现中文目录乱码问题的解决方法【转】
- 通过freemarker生成一个word,解决生成的word用wps打开有问题的问题,解决出word时中文文件名乱码问题,解决打开出word时打开的word出现问题的问题,出图片,解决动态列表
- XML序列化对象时出现中文乱码
- Web Deployment Project生成的web.config中文出现乱码
- win7 64位系统使用VS2010生成时出现中文目录乱码问题的解决方法
- dom4j生成xml显示中文
- jsp获取JavaScript生成的中文cookie出现乱码问题解决方法
- dom4j 输出UTF-8 XML时中文乱码
- 如何防止XMLHttpRequest对象传回的中文数据中出现乱码?
- php生成中文文件时,文件出现乱码
- 写了一个查询数据库的程序,不熟的Tomcat6。查询条件为英文时运行正常,为中文时出现乱码。后在tomcap的server.xml中加入useBodyEncodingForURI="true解决了问题
- 使用XMLWorkerHelper.getInstance().parseXHtml生成PDF时中文不显示或乱码问题
- php zend framework 生成 pdf 出现中文乱码
- tiny中文乱码问题,不过仅适用于windows,所以xml不可以出现中文
- “用dom4j解析包”对xml进行dom方式操作中文乱码解决方案
- dom4j生成xml文件的中文乱码