[jdom-interest] Deprecating some XMLOutputter constructors

guru at stinky.com guru at stinky.com
Tue Jun 19 11:00:00 PDT 2001


On Tue, Jun 19, 2001 at 01:39:47PM -0400, Alex Rosen wrote:
> All these are fine with me.
> 
> I do want to note that I think that much of the time when people are
> pretty-printing, they will NOT want their text normalized. For most
> data-oriented uses, normalization will at best waste cycles; at
> worse, it will lose meaningful information.

Unfortunately, then when you pretty-print text that's already pretty,
it becomes less so.

If your input is a file containing

<hello>
  my honey
  <hello>my baby</hello>
</hello>

Then XMLOutputter("  ", true) (no normalization) will give you

<?xml version="1.0" encoding="UTF-8"?>
<hello>
  
  my honey
  
  <hello>my baby</hello>
  

</hello>

If we replace indent with "__" it becomes easier to see the whitespace
left over from the document :

$ ./output.sh -indent '__' -newlines  /tmp/hello.xml 
<?xml version="1.0" encoding="UTF-8"?>
<hello>
__
  my honey
  
__<hello>my baby</hello>
__

</hello>

I'm not quite sure why trimText got replaced with textNormalize, since
merely stripping whitespace immediately after the start tag is less
expensive computationally, and possibly more useful overall, since it
allows you to preserve things like <pre> blocks where internal
whitespace is significant, but surrounding whitespace is not.

For example:

<p>
  <pre>
one
two
three
  </pre>
</p>

Output with indent + newlines + textNormalize:
<p>
  <pre>one two three</pre>
</p>

Output with indent + newlines + textTrim:
<p>
  <pre>one
two
three</pre>
</p>

Output with indent + newlines only:
<p>

  <pre>
one
two
three
  </pre>


</p>


Notice the ugly (= not pretty) extra newlines in the final one (which
is what you recommended).

Should we bring back trimText?  Should we allow the user to set the
"what counts as whitespace" string?

-- 
Alex Chaffee                       mailto:alex at jguru.com
jGuru - Java News and FAQs         http://www.jguru.com/alex/
Creator of Gamelan                 http://www.gamelan.com/
Founder of Purple Technology       http://www.purpletech.com/
Curator of Stinky Art Collective   http://www.stinky.com/



More information about the jdom-interest mailing list