zoukankan      html  css  js  c++  java
  • 随题而学(四)xml文件格式规范化

    保存xml时,为使其生成的文件格式规范化,可对TransformerFactory设置输出属性,如下。

    transformer.setOutputProperty(OutputKeys.INDENT, "yes");
    transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2");
    /**
         * 
         * @param folderPath
         * @param document
         */
        private static void saveXML(String folderPath, Document document) {
            String filePath = folderPath + File.separator + "test.xml";
            try {
                TransformerFactory tFactory = TransformerFactory.newInstance();
                Transformer transformer = tFactory.newTransformer();
                transformer.setOutputProperty(OutputKeys.INDENT, "yes");
                transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2");  
                
                DOMSource source = new DOMSource(document);
                StreamResult result = new StreamResult(new File(filePath));
                transformer.transform(source, result);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
  • 相关阅读:
    # ES6基础
    # yarn简单使用
    # laravel框架中的配置
    需求概述开发进度09
    需求概述开发进度08
    需求概述开发进度07
    需求概述开发进度06
    需求概述开发进度05
    需求概述开发进度04
    需求概述开发进度03
  • 原文地址:https://www.cnblogs.com/yunkong/p/4402942.html
Copyright © 2011-2022 走看看