[jdom-interest] problem with XMLOutputter and CDATA

Wesley Biggs wbiggs at elite.com
Tue Mar 6 14:19:45 PST 2001

Hi Karsten--

You need to call Element.getMixedContent().  This will return you a List
including the CDATA as an org.jdom.CDATA object, and the getText() method on
that will get you what you need.

The ability to get CDATA should be added to the Javadoc for
Element.getMixedContent() -- it currently only mentions


-----Original Message-----
From: Karsten Opitz [mailto:Karsten_Opitz at CoCreate.com]
Sent: Tuesday, March 06, 2001 1:22 PM
To: jdom-interest at jdom.org
Subject: [jdom-interest] problem with XMLOutputter and CDATA

I'm using the XMLOutputter with indent=true & newline=true because I do need
the formatted output for several reasons

Now I'm writing a CDATA section, e.g. 
    <![CDATA[aaaa         bbb]]>

When I read that back in, I have two choices

(1) getText          ==> "\n   aaaa      bbb\n"
(2) getTextTrim ==> "aaaa  bbb"

Neither of these strings are satisfactory, how can I get the original block
back ? As a workaround, I'm using
    String str = elem.getText();
Of course, that's not safe either. What if my block of binary data happens
start with a whitespace ?

Any suggestions for a workaround ? Maybe an enhancement request for the
XMLOutputter ?


Karsten Opitz
CoCreate Software Inc.
3801 Automation Way, Suite 110
Fort Collins, CO, 80525
www : http://www.cocreate.com
Phone : (970) 267-8161
Fax : (970) 267-8001
e-mail : karsten_opitz at CoCreate.com

To control your jdom-interest membership:

More information about the jdom-interest mailing list