1、文件形式:
xmlwriter writer = null;
/** 格式化输出,类型ie浏览一样 */
outputformat format = outputformat.createprettyprint();
/** 指定xml编码 */
format.setencoding("gbk");
try{
writer= new xmlwriter(new filewriter(new file("test.xml")),format);//用fileoutputstream更好。
writer.write(document);
writer.close();
}
catch(ioexception ioe){ioe.printstacktrace();}
2、string形式,我现在做的框架中,是po<-->xml--servlet,不需要生成文件,搜索了半天没搜索出来,后来干脆自己试出来了。
stringwriter sw=new stringwriter();
xmlwriter writer = null;
outputformat format = outputformat.createprettyprint();
format.setencoding("gbk");
writer=new xmlwriter(format);
writer.setwriter(sw);
writer.write(document);
system.out.println(sw.tostring());
闽公网安备 35060202000074号