`

How to transform DOM into String

    博客分类:
  • XML
阅读更多
/**
* Prints a textual representation of a DOM object into a text string..
     *
* @param document DOM object to parse.
* @return String representation of <i>document</i>.
*/
    static public String toString(Document document) {
        String result = null;
       
        if (document != null) {
            StringWriter strWtr = new StringWriter();
            StreamResult strResult = new StreamResult(strWtr);
            TransformerFactory tfac = TransformerFactory.newInstance();
            try {
                Transformer t = tfac.newTransformer();
                t.setOutputProperty(OutputKeys.ENCODING, "iso-8859-1");
                t.setOutputProperty(OutputKeys.INDENT, "yes");
                t.setOutputProperty(OutputKeys.METHOD, "xml"); //xml, html, text
                t.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "4");
                t.transform(new DOMSource(document.getDocumentElement()), strResult);
            } catch (Exception e) {
                System.err.println("XML.toString(Document): " + e);
            }
            result = strResult.getWriter().toString();
        }
           
        return result;
    }//toString()
分享到:
评论

相关推荐

    Hacking - Firewalls And Networks How To Hack Into Remote Computers.pdf

    原版Hacking - Firewalls And Networks How To Hack Into Remote Computers.pdf

    C++ How to Program, 10th Edition

    C++ How to Program (10th Edition) By 作者: Harvey M. Deitel Paul Deitel ISBN-10 书号: 9332585733 ISBN-13 书号: 9789332585737 Edition 版本: 10th 出版日期: 2017 Format: Paperback C++ How to Program ...

    linux howto中文合集

    HOWTO-html&lt;br&gt;News-HOWTO-html&lt;br&gt;News-Leafsite-html&lt;br&gt;Oracle-HOWTO-html&lt;br&gt;Plug-and-Play-HOWTO-html&lt;br&gt;PPP-HOWTO-html&lt;br&gt;Printing-HOWTO-html&lt;br&gt;QT 3.3 中文白皮书.pdf Quota RCS-...

    How To Listen (Public) 2.0.4 Setup.zip

    "How To Listen"是一款专为提升用户听力敏感度和音质辨识能力设计的训练软件,尤其适用于音乐制作人、音频工程师以及任何对声音有高要求的人群。这个名为"How To Listen (Public) 2.0.4 Setup.zip"的压缩包包含了该...

    HowTo2152.zip_howto2152

    包含了将近100张图表,这些图表能用来根据载流能力和温度限制条件来精确估计导线的宽度,这个Excel工具允许设计者根据不同的叠层结构和设计条件填入不同的数值来计算导线宽度。很简单的在绿色单元格内输入项目的设计...

    最基础的听力训练和测试——哈曼How to listen

    《哈曼How to listen:开启你的听力训练之旅》 听力训练是提升个人听力敏锐度的重要途径,尤其对于音乐爱好者和专业音频工作者来说更是必不可少。哈曼How to listen是一款专为耳朵训练而设计的软件,旨在帮助用户...

    Linux Howto 中文文档

    Linux HOWTO(中文版) BootPrompt-HOWTO (28KB) 启动提示说明 CDROM-HOWTO (27KB) 如何安装, 设定及使用光驱,同时列出支援的硬体. Chinese-HOWTO (39KB) 如何在 Linux 的系统上使用中文?/TD&gt; Config-...

    How To Write A Dissertation

    How To Write A Dissertation

    how to solve it

    Polya, "How to Solve It" will show anyone in any field how to think straight. In lucid and appealing prose, Polya reveals how the mathematical method of demonstrating a proof or finding an unknown ...

    C++大学教程C++ How to Program(中英文)

    《C++ How to Program》是C++编程领域的一本经典教材,由保罗·戴特尔(Paul Deitel)和哈维·戴特尔(Harvey Deitel)共同编写,提供了全面且深入的C++学习资源。该教程分为第九版(9E)和第十版(10E),并提供中...

    HTML DOM基础教程(网页形式)

    DOM How To DOM 参考 DOM 总结 DOM 实例 DOM 实例 DOM 对象 DOM Window DOM Navigator DOM Screen DOM History DOM Location DOM Document DOM Anchor DOM Area DOM Base DOM Body DOM Button DOM ...

    Linux中文HOWTO

    Linux中文HOWTO Linux中文HOWTO Linux中文HOWTO

    RK3399的DRM-HOWTO测试

    RK3399的DRM-HOWTO测试 最近在学习与调试RK3399的DRM显示架构,网上有很多例程,其中介绍比较多的是来于David Herrmann’s Github的drm-howto.开源代码 但这些源码下载后执行make编译出来的执行文件只能在PC机上测试...

    How to Learn Any Language

    How to Learn Any Language 全英!!!

    how to how to how to

    how to

    Exploiting Software - How to Break Code.rar

    Exploiting Software - How to Break Code.rar

    How to use SFTP

    How to use SFTP (with client validation - public key authentication) The topic How to use SFTP (with client validation - password authentication) discusses the simplest form of client ...

    how to listen 测音软件 训练金耳朵

    软件为测试听音软件 可以自定义语音、训练自己的耳朵可以分辨音频的细微差别

Global site tag (gtag.js) - Google Analytics