OutputFormat 设置xml编码和格式内容

        rootElement.add(new DefaultNamespace("http", "www.baidu.com"));
        //写出
         format = OutputFormat.createCompactFormat();
//      OutputFormat fs = OutputFormat.createPrettyPrint();
        format.setEncoding("GBK");
        
        FileOutputStream oStream = new FileOutputStream("./src/write2.xml");
        XMLWriter writer = new XMLWriter(oStream, format);
    
        writer.write(document);
        writer.flush();
        oStream.close();

你可能感兴趣的:(OutputFormat 设置xml编码和格式内容)