Original method:
public void oldWriteXML() throws Exception{ storeDoc.normalize(); //storeDoc is type Document if (storeFile!=null){ storeFile.delete(); //delete the old file to overwrite } OutputStreamWriter fos = new FileWriter(filename); OutputFormat format = new OutputFormat(storeDoc); format.setLineWidth(65); format.setIndenting(true); format.setIndent(2); XMLSerializer serializer = new XMLSerializer(fos, format); serializer.serialize(storeDoc); fos.close(); }
New method to allow UTF-8:
public void writeXML() throws Exception{ storeDoc.normalize(); if (storeFile!=null){ storeFile.delete(); } OutputStreamWriter fos = new OutputStreamWriter(new FileOutputStream(filename),"UTF-8"); OutputFormat format = new OutputFormat(storeDoc, "UTF-8", true); format.setLineWidth(65); format.setIndent(2); XMLSerializer serializer = new XMLSerializer(fos, format); serializer.serialize(storeDoc); fos.close(); }
No comments:
Post a Comment