[jdom-interest] XHTML issues

Rachel Greenham rachel at linuxgrrls.org
Wed Aug 13 08:50:27 PDT 2003


Elliotte Rusty Harold wrote:
> At 11:21 PM +0100 7/25/03, Rachel Greenham wrote:
> 
> 
>> The other issue I had by the way was that EntityRefs are being printed 
>> out with surrounding newlines if newlines is true on the XMLOutputter. 
>> This has the effect that they get surrounded by a visible space when 
>> displayed in a browser. When you're using entities for quote marks, 
>> apostrophes, and accented letters (most of the time in fact) this is 
>> obviously not wanted. However, setting the XMLOutputter to not 
>> generate newlines makes the source very unpleasant and difficult to 
>> look at manually (eg: a 30,000 word story crushed to 66 logical lines, 
>> most of those in a <pre> block, for instance).
> 
> 
> 
> Hmm, that really sounds like a bug. Entity references should not be 
> surrounded by newlines even when indenting for the reasons you cite. Has 
> anyone fixed this yet? If not, I could give it a shot.

My solution was to extend XMLOutputter and override printElement() (I think, 
this was weeks ago and I'm not looking at it right now). Then I just watched 
out for <p> elements (sufficient due to the simplicity of the document I'm 
generating) and turned off and on newlines either side of a call to the 
superclass method. :-)

Thinking about it, a fuller, but *slower*, solution would be to scan the 
element's contents (but not into children) and only do so if there are any 
EntityRefs found.

BTW, I guessed, rather than trying it, that overriding printEntityRef 
wouldn't work because the newlines would be inserted before/after that 
method is called. I suspect this is so by the token that overriding 
printElement that way doesn't stop each of my paragraph elements turning up 
on their own line.

-- 
Rachel





More information about the jdom-interest mailing list