I've got a pretty serious problem with XML Creation using standard java objects, my code is as follows:
//Generate DOM
DOMSource source = this.generateDomDocument(params...);
//WRITE XML FILE
TransformerFactory transformerFactory = TransformerFactory.newInstance();
Transformer transformer = transformerFactory.newTransformer();
//Properties
transformer.setOutputProperty(OutputKeys.DOCTYPE_SYSTEM, STRING_FIELD_DTD);
transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "4");
transformer.setOutputProperty(OutputKeys.INDENT, "yes");
//Convert and write to disk
transformer.transform(source, new StreamResult(
new OutputStreamWriter(new FileOutputStream(fileName), "UTF-8")));
Problem is, the transformer is transforming Carriage Returns in
entities which I should not have in the resulting XML. This is an example, I have a result file with translations written in several different languages (that's why I use UTF-8) and they are all the same when they contain CarriageReturns in the text:
<content langID="EN">
<desc> Test string
do not copy.</desc>
To clear things up, this is what I expect in the XML:
<content langID="EN">
<desc> Test string
do not copy.</desc>
I looked up the issue on google and here too but there seems to be no solution or workaround.