public static void execute(/*一些参数*/) throws Exception { filepath = "D:\\form.xml"; SAXReader reader = new SAXReader(); Document doc = reader.read(new File(filepath)); //......一些处理 XMLWriter xmlWriter = new XMLWriter(new FileOutputStream(filepath)); xmlWriter.write(doc); xmlWriter.close(); }
得到的xml文件里面的"变成了双引号,>没变。
我想让他都不变,"还是",不要变成双引号
saxRead.setEncoding("UTF-8");指定你使用的格式,GB2312
OutputFormat format = OutputFormat.createPrettyPrint(); format.setEncoding("utf-8"); XMLWriter writer = new XMLWriter(new OutputStreamWriter(new FileOutputStream(filename), "utf-8"), format); writer.write(document); writer.close();
<script> <![CDATA[ function matchwo(a,b) { if (a < b && a < 0) then { return 1; } else { return 0; } } ]]></script>