[jdom-interest] CDATA and XMLOutputter - problem with normalization

Elliotte Rusty Harold elharo at metalab.unc.edu
Sun Apr 25 10:09:36 PDT 2004

At 8:26 AM +0100 4/22/04, Rick Beton wrote:

>According to my (perhaps naive) understanding of what a CDATA is, it's
>just 'stuff' and it shouldn't be formatted or normalised at all.  If my
>understanding is right, then the method should be simplified to

Don't confuse character data with a CDATA section, though perhaps the 
class name is a little off. I would prefer it to be called 
CDATASection rather than just CDATA.

And if you don't want it formatted or normalized, then don't tell the 
outputter to format or normalize anything. It only does that if you 
tell it to. It never formats or normalizes by default.

>protected void printCDATA(Writer out, CDATA cdata) throws IOException {
>      out.write("<![CDATA[");
>      out.write(cdata.getText());
>      out.write("]]>");
>I came across this because of trying to generate XHTML with Javascript
>nodes. The Javascript may happen work when normalised. However, if it
>happens to contain '//' comments (in which the whitespace line ending is
>significant), then
>the normalisation will quite likely break the Javascript and is clearly
>undesirable.  Formatters shouldn't attempt to pretty-up something that
>is inherently opaque.

Again, it only does that because you asked it to.

>2. My more general question is this: I noticed that org.jdom.CDATA
>extends org.jdom.Text. What is the rationale for CDATA extending Text?

CDATA is a Text. It's that simple, The relaitonship is correct.

>org.jdom.Text represents XML 'character data'.

Yes it does, but character data is not a CDATA section. You are 
misreading the XML specification.


   Elliotte Rusty Harold
   elharo at metalab.unc.edu
   Effective XML (Addison-Wesley, 2003)

More information about the jdom-interest mailing list