Hi Laramie

I'm CC'ing the dom4j-dev list to see if others have any ideas.  You raise an
interesting problem that I'd not considered before. Maybe the XMLWriter and
HTMLWriter could be refactored a bit so that the trimming mode is
enabled/disabled based on which element its inside. e.g. the OutputFormat
could get its trimtext mode swizzled based on the element name, so that pre,
script, style tags always come out without trimtext.

Do you fancy having a play with the source and trying to implement what you
need?

James
----- Original Message -----
From: "Laramie Crocker" <[EMAIL PROTECTED]>
> Hi,
>
> I'm wondering if there is some sample code somewhere or some pointers you
> could offer
> on how to correctly preserve the line returns in script, style, and pre
> tags?
>
> I turn on newlines and trimtext, otherwise I don't get pretty printing.
> But with those options on, script, pre, and style tags get folded onto one
> line.
> These tags (and perhaps a few others) should have whitespace preserved
> internally.
> I can't use a CDATA wrapper, since javascript doesn't like it.
>
> For script and style, I can use html comments, which are fine since both
of
> those tags are OK with comments (and some browsers require them).
>
> But for pre, I'm pretty much outta luck.  In my application, I would like
> prettyPrinting, but folding a pre section defeats the purpose of pre.
>
> Also, I can't see an *easy* way to turn off entity expansion.  I could set
> an entity resolver, but it seems like overkill just to make sure that &
> #160; doesn't get expanded.
>
> If there is not some option I am missing, then I guess my best plan would
be
> to subclass HTMLWriter.  But it seems that one could set a List of tags
> (with a setter, and a default) in HTMLWriter that should not be dived
into.
> The default would be pre, script, and style.
>
> Any ideas would be appreciated,
>
> thanks,
> Laramie
>
> P.S. Here is my test code:
>
>             ByteArrayOutputStream bos =  new ByteArrayOutputStream();
>             PrintStream out = new PrintStream(bos);
>             org.dom4j.io.OutputFormat format =
> org.dom4j.io.OutputFormat.createPrettyPrint();
>             format.setNewlines(true);
>             format.setTrimText(true);
>             org.dom4j.io.HTMLWriter writer = new
> org.dom4j.io.HTMLWriter(out, format);
>             org.dom4j.Document document =
> org.dom4j.DocumentHelper.parseText(html);
>             writer.write(document);
>             writer.flush();
>             out.close();
>             return bos.toString();
>
> try-catch ommitted...
>
>
>
>


_______________________________________________
dom4j-dev mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/dom4j-dev

Reply via email to