REXML, pretty print + transitive and CDATA nodes

My attempt to post this on the REXML JitterBug failed (which is probably
just as well as I learned one more tidbit since that attempt.

Basically, I would like to have pretty printing on as well as
transitive. I see in the rexml_stable todo that this has been crossed
off, and isn’t mentioned in the main branch page either.

The write() method for CData nodes ignores the transitive flag. This
snippet of code illustrates the example:

require ‘rexml/document’

doc = REXML::Document.new()
root = REXML::Element.new(‘package’, doc)

REXML::CData.new(“somestr”, true, root)

file = STDOUT
doc.write(file, -1, true)
file.puts “\n\n”
doc.write(file, 0, true)

OUTPUT:

</package

The extra spaces before the start of the CDATA node change what
the actual document contains rather than just its presentation.
I’m not actually sure why the line is being split on the pretty print
(that started happening when I began passing transitive as true, which
is what I wasn’t doing when I tried to submit the issue on Jitterbug).

Is this something that is possible to fix? Or has it been deemed
unworthy? If so, does anyone have a workaround? Right now I’ve just
shut pretty printing off. This is undesirable since there are many
occasions when the output will be viewed and/or edited by hand after output.

Thanks,

Brett

Brett Williams brett_williams@agilent.com wrote in message news:1084203997.803240@cswreg.cos.agilent.com

My attempt to post this on the REXML JitterBug failed (which is probably
just as well as I learned one more tidbit since that attempt.

I’ve added this to the bug repository as bug #23

Please modify the bug and set the version information from the results
of the following code:

ruby -rrexml/rexml -ve 'puts REXML::Version'

Or email it to me directly, and I’ll add it.

— SER

Brett Williams brett_williams@agilent.com wrote in message news:1084203997.803240@cswreg.cos.agilent.com

The write() method for CData nodes ignores the transitive flag. This
snippet of code illustrates the example:

This is fixed; it’ll be in CVS before the end of the day, and will be
in REXML 3.0.7.

CData is supposed to ignore the transitive flag, but other things were
occurring that caused errors and other misformattings. CData sections
will not be formatted, because they “raw” data, and whitespace in
CData sections is always significant. Therefore, REXML will not add
whitespace to CData sections; also, since the “magical” markup of the
CData end, namely “]]>” is a block of characters, we can’t apply the
normal trick of inserting a CR before the close ‘>’. The only place
to insert whitespace would be before the “]]>” (which would be adding
whitespace to the CData section, which is illegal), or after the
“]]>”, which would add a Text node to the tree, which would be illegal
for transitive documents.

Therefore, the XML document:

<a><![CDATA[ Lalalala ]]></a>

will be transitively printed as:

<a
  ><!CDATA[ Lalalala ]]></a
>

Which is about as good as we can get. This is still better than what
REXML was doing before, which was crashing :-).

— SER