File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes XML and Related Technologies and the fly likes JDOM and CDATA Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "JDOM and CDATA" Watch "JDOM and CDATA" New topic


Dave Hewy
Ranch Hand

Joined: Aug 21, 2003
Posts: 93
I have an attribute in my XML, something like <field=abcdefghi/>
I need to insert a CRLF after abc and after def so that when output it's shown as
so in my java I have something like
I have found out that the parser will strip out the LF and leave the CR between each one, but I need to retain BOTH.
Am I right in thinking that CDATA will allow me to do this?
If so, how can I accomplish this using JDOM for my attribute? I can see how you do it as an element.
Lasse Koskela

Joined: Jan 23, 2002
Posts: 11962
Would it be ok to just go through the resulting string/file and add the missing '\r' where it's missing?

Author of Test Driven (2007) and Effective Unit Testing (2013) [Blog] [HowToAskQuestionsOnJavaRanch]
Dave Hewy
Ranch Hand

Joined: Aug 21, 2003
Posts: 93
Well I thought that might do it, so I tried it out, but it didn't seem to work.
Then I remembered that the receiver of the XML is using the MS XML parser, which is probably doing exactly the same thing! DOH!
This will have to be sorted out at their end !
Thanks anyway.
I agree. Here's the link:
subject: JDOM and CDATA
It's not a secret anymore!