[jdom-interest] d-o-e, rendering embedded HTML and XMLOutputter

Les Hill leh at galaxynine.com
Mon Apr 15 08:46:07 PDT 2002


Gary Lawrence Murphy <garym at canada.com> writes:
>This problem has taken me across three mailing lists, and I'm not
>getting any closer ... but I do have some evidence it's a problem
>with the way I am using transformation on JDOM objects.

<answer>
<warning rant="on"/>

Having run across this usability problem, as well as many others :), let me
say that this is not really a problem with JDOM or your transformation but
rather with the XMLOutputter (a convenience/utility class).  The
XMLOutputter is escaping the text.  The "get it done now" answer is to build
your own.  In this case:

public class HTMLOutputter extends XMLOutputter
{
    public HTMLOutputter()
    {
        super();
    }

    public HTMLOutputter(String indent)
    {
        super(indent);
    }

    public HTMLOutputter(String indent, boolean newlines)
    {
        super(indent, newlines);
    }

    public HTMLOutputter(String indent, boolean newlines, String encoding)
    {
        super(indent, newlines, encoding);
    }

    public HTMLOutputter(HTMLOutputter that)
    {
        super(that);
    }

    // You may or may not want this
    public String escapeAttributeEntities(String str)
    {
        return str;
    }

    public String escapeElementEntities(String str)
    {
        return str;
    }
}

<suggestion>
For the longer term, perhaps XMLOutputter could have added functionality to
control the escaping behaviour (this is a suggestion from way, way, back in
history), or an HTMLOutputter (or other name) subclass could be added to
JDOM extending XMLOutputter with the functionality (a bit more robust than
the above :).
</suggestion>

<rant>


More information about the jdom-interest mailing list