I am writing a Xml Tag RenamerJava class that reads in XML, renames tags, and writes them back to another XML file using DocumentBuilderFactoryand TransformerFactory(text nodes are saved). It worked perfectly with German and English texts until today, when I tried to rename the XML file with Russian text. Instead of the source code, I got it ?????in a newly created XML file. I tried to set the encoding
Any idea how to fix this?
PS. The lines were correct before injecting TransformerFactory, as I checked in the debugger. I tried installing OutputKeys.ENCODINGon UTF-8and ISO-8859-5. None of them helped.
Transformer Part:
TransformerFactory transFactory = TransformerFactory.newInstance();
Transformer transformer = transFactory.newTransformer();
transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "no");
transformer.setOutputProperty
("{http://xml.apache.org/xslt}indent-amount", "4");
transformer.setOutputProperty(OutputKeys.INDENT, "yes");
transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8");
StringWriter sw = new StringWriter();
StreamResult result = new StreamResult(sw);
DOMSource source = new DOMSource(doc);
transformer.transform(source, result);
String xmlString = sw.toString();
xmlString.replaceAll("\n", System.getProperty("line.separator"));
BufferedWriter output = new BufferedWriter(new FileWriter(outputPath));
output.write(xmlString);
output.close();