[jdom-interest] Bug in CDATA reading/writing?
Jason Hunter
jhunter at collab.net
Wed Mar 14 13:28:30 PST 2001
Mark Roder wrote:
>
> I am using JDOM-B6.
>
> I am noticing if I read a file, write a file and then read it back in again,
> I get different data the second time I read it when the file contains CDATA.
>
> This seems weird to me. Is this a bug in the code or something that should
> be documented some more? It was surprising to me.
It's working as spec'd.
> //Breaks things on next line
> //XMLOutputter xmlOut = new XMLOutputter("",true);
> //XMLOutputter xmlOut = new XMLOutputter(" ",true);
The "true" indicates to add new lines. Thus it adds new lines.
> //Breaks adds the spaces to the front
> //XMLOutputter xmlOut = new XMLOutputter(" ");
> //XMLOutputter xmlOut = new XMLOutputter(" ",false);
The " " indicates to add a two-space indent. Thus it adds a two-space
indent.
> //Works
> //XMLOutputter xmlOut = new XMLOutputter("");
> //XMLOutputter xmlOut = new XMLOutputter("",false);
> XMLOutputter xmlOut = new XMLOutputter();
The "" and false say not to add indenting or new lines. Thus your
output is the same as your input.
Since by default in XML all whitespace is preserved, you generally want
to output without adding any new whitespace. But if you create elements
in-memory then you probably don't add padding whitespace so you want the
outputter to add the padding for you. That's why you have that option.
-jh-
More information about the jdom-interest
mailing list