首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 软件管理 > 软件架构设计 >

Java w3c dom的合龙与格式化输出

2012-09-18 
Java w3c dom的合并与格式化输出遇到需要将几个W3C标准的Document文档简单合并,一个主文档,其他的文档并列

Java w3c dom的合并与格式化输出
遇到需要将几个W3C标准的Document文档简单合并,一个主文档,其他的文档并列按照顺序放在主文档的孩子节点上就行了。。。

    

public static String toString(Document doc) throws TransformerFactoryConfigurationError, TransformerException{ DOMSource source = new DOMSource(doc);         StringWriter writer = new StringWriter();         Result result = new StreamResult(writer);         Transformer transformer = TransformerFactory.newInstance().newTransformer();         transformer.setOutputProperty(OutputKeys.INDENT, "yes");         transformer.setOutputProperty(OutputKeys.CDATA_SECTION_ELEMENTS, "yes");       transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2");        transformer.transform(source, result);         return (writer.getBuffer().toString());} 


transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2");

原文出自:http://charyle.iteye.com/blog/1193846

热点排行