Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Transformer inserts extra carriage returns into CDATA sections

843834Aug 21 2006 — edited Aug 23 2006
Hi,

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
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Sep 20 2006
Added on Aug 21 2006
6 comments
711 views