OutputFormat format = OutputFormat.createPrettyPrint(); XMLWriter writer = new XMLWriter( out, format ); writer.write( document ); writer.close(); |
|
public static String format(Document document){
StringWriter writer = new StringWriter();
OutputFormat format = OutputFormat.createPrettyPrint();
format.setEncoding("gb2312");
XMLWriter xmlwriter = new XMLWriter( writer, format );
try {
xmlwriter.write(document);
} catch (Exception e) {
e.printStackTrace();
}
return writer.toString();
}
|
使用write(Document的结果: doc)
|
<?xml version="1.0" encoding="gb2312"?>
<DSTreeRoot text="root
根
" open="true">
<DsTree text="
节点
1" open="true"/>
<DsTree text="
节点
2" open="true"/>
</DSTreeRoot>
|
使用write(String的结果: text)
|
<?xml version="1.0" encoding="UTF-8"?> <DSTreeRoot text="root
根
" open="true"><DsTree text="
节点
1" open="true"/><DsTree text="
节点
2" open="true"/></DSTreeRoot>
|
478




被折叠的 条评论
为什么被折叠?



