[jdom-interest] Bug in CDATA reading/writing?

Jason Hunter jhunter at collab.net
Thu Mar 15 08:05:24 PST 2001


> To me having:
>     protected void printCDATASection(...)
>     {
>         indent(out, indentLevel);
>         out.write(cdata.getSerializedForm());
>         maybePrintln(out);
>     }
> is just like having the code read like this - and this makes no sense to me.
>    protected void printString(...)
>    {
>         indent(out, indentLevel);
>         out.write(string);
>         maybePrintln(out);
>    }
> 
> Wouldn't the following changes "fix" this?
>     protected void printCDATASection(...)
>     {
>         out.write(cdata.getSerializedForm());
>     }

The existing code allows for pretty printing if you request it:

<root>
  Here is some text
  <![CDATA[Here is some CDATA]]>
  And here is more text
</root>

If you create "new XMLOutputter()" there'll be no whitespace added (no
indent or new lines).  You have to request having it added.  Perhaps
CDATA is a special case where you wouldn't want it ever to appear on a
separate line if it's surrounded by strings.

> Am I way off base here?  To me it looks like XMLOutputter is tainting data.

Not really.  If you create an XMLOutputter with indent and new lines,
then you've expressly said that preserving whitespace isn't important.

This make sense?  Let me know if you think you found a bug.  There were
reports of bugs involving CDATA whitespace, but I couldn't reproduce.

-jh-



More information about the jdom-interest mailing list