OutputFormat format = OutputFormat.createPrettyPrint();//缩减型格式
            //OutputFormat format = OutputFormat.createCompactFormat();//紧凑型格式
            format.setEncoding("gb2312");//设置编码
            //format.setTrimText(false);//设置text中是否要删除其中多余的空格
            XMLWriter xw = new XMLWriter(fw, format);
           xw.write(doc);

解决方案 »

  1.   

    FileWriter fw = new FileWriter("test.xml");
      

  2.   

    callWriteXmlFile方法里面有这么一句,就是用来设置输出格式的啊
    XMLOutputter xmlOut = new XMLOutputter(Format.getPrettyFormat()); 
      

  3.   

    在你的这个xformer.setOutputProperty(OutputKeys.ENCODING, encoding); 后面加上这两句properties.setProperty(OutputKeys.INDENT, "yes");
    properties.setProperty(""{http://xml.apache.org/xslt}indent-amount"", "4");
      

  4.   

    对不起应该是xformer.setOutputProperty(OutputKeys.INDENT, "yes");
    xformer.setOutputProperty(""{http://xml.apache.org/xslt}indent-amount"", "4");