DOM4j处理XML文件时,写入文件后发现XML文件很多空行,而且文件也变大了,我现在是用XML文件来传输数据,不知道怎么处理这种问题.
解决方案 »
- 如何解决 connection reset by peer:socket write error 问题??
- javascrip中的数组问题
- 编写程序输出一年12个月所对应的天数
- BufferedReader#readline()发生莫名IllegalArgumentException异常
- 初学java的一篇不错的文章,通俗易懂,强烈推荐!看完记得顶起!!
- 用JAVAC编译程序时太多错误不能一个屏幕显示出来怎么办?
- string 与 double
- C++中虚拟函数表的问题
- jdbc数据库连接问题
- corba中exception处理的小问题(最多只能给这么多分了)
- 有没做过联通短信接口的人啊 ,这几天在测接口遇到点问题.....
- java播放音频文件的功能
format.setEncoding("utf-8");
format.setIndent(" ");
XMLOutputter XMLOut = new XMLOutputter(format);
XMLOut.output(Doc, new FileOutputStream(xmlname));
Document document = DocumentHelper.createDocument();
XMLWriter writer = null;
OutputFormat format = OutputFormat.createPrettyPrint();
format.setEncoding("UTF-8");
format.setExpandEmptyElements(true);
format.setTrimText(false);
format.setIndent(" ");
* 通过 org.dom4j.io.OutputFormat 来设置XML文档输出格式
*/
OutputFormat format = OutputFormat.createPrettyPrint(); // 设置XML文档输出格式
format.setEncoding("UTF-8"); // 设置XML文档的编码类型
format.setSuppressDeclaration(true);
format.setIndent(true); // 设置是否缩进
format.setIndent(" "); // 以空格方式实现缩进
format.setNewlines(true); // 设置是否换行 try {
/** 将document中的内容写入文件中 */
XMLWriter writer = new XMLWriter(new FileWriter(new File(
xmlFileName)), format);
writer.write(this.getDocument());
writer.close();
} catch (Exception ex) {
System.out.println(ex.getMessage());
}
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
Document doc = builder.parse(xmlFile);
.
.
.
.
.
FileWriter fw = new FileWriter(xmlFile);
OutputFormat format = OutputFormat.createPrettyPrint();
format.setEncoding("GBK");
format.setExpandEmptyElements(true);
format.setTrimText(false);
format.setIndent(" ");XMLWriter xmlw = new XMLWriter(fw,format);
xmlw.write(doc);xmlw.flush();
xmlw.close();