Transformer inserts extra carriage returns into CDATA sections
843834Aug 21 2006 — edited Aug 23 2006Hi,
I'm using an identity transformer to convert a DOM source into an XML document. I've noticed that the transformer will insert a carriage return character before any line feed character. So for example if I put the following text into a CDATA section:
Line 1\r\nLine 2\r\nLine 3
I get the following CDATA section in my document:
<![CDATA[Line 1\r\r\nLine2\r\r\nLine3]]>
(note the extra \r character before each \n character). The code I'm using is:
ByteArrayOutputStream out=new ByteArrayOutputStream();
DOMSource domSource = new DOMSource(xmlDoc);
StreamResult streamResult = new StreamResult(out);
TransformerFactory tf = TransformerFactory.newInstance();
Transformer serializer = tf.newTransformer();
serializer.transform(domSource, streamResult);
I've tried all combinations of output properties to no avail. Is there a way to stop this from happening?
Thanks,
Wyatt