[jdom-interest] character entity resolution?

Jason Hunter jhunter at apache.org
Sat Apr 27 11:12:16 PDT 2002

If you call elt.setText("<xml> content"); then on output it will write
"&lt;xml&gr; content" because that's what you passed in and it needs to
escape special characters to keep the same semantic meaning.

JDOM doesn't do any magical attempt to parse the content you provide as
XML.  Imagine the slowness!  

Some people have hacked the outputter to disable encoding, and you could
do that, but it's a very bad idea to try to save XML or HTML as text and
output it raw.  You're mixing two metaphors, and it'll bite you at some


> cocoonlist78 wrote:
> JDOM users:
>   I'm not sure if this is related to JDOM or not but maybe someone has
> an idea:
>   I'm creating a web interface for editing XML documents.  The form
> submits to a servlet that reads the existing XML document in and
> represents it with JDOM.  I use setText() on the various Elements
> to make changes based on the form data and then write out the new XML
> file with XMLOutputter.output().  Some of the form fields contain XML
> tags (for inline stuff like <italic> and <bold>).  Somewhere in the
> process those inline XML tags that are coming across the CGI are being
> changed from <italic> to &lt;italic&gt;.  This of course causes
> problems because when the XML file is parsed these tags are seen as
> strings rather than nodes.
> I've used System.out to check the strings and I don't see any entity
> references as far as the servlet is concerned.  Maybe System.out
> resolves them...
> Is there anything in the XMLOutputter.output()  or Element.setText()
> methods that resolves these characters to HTML entities?  Any ideas?
> Suggestions?
> Thanks

More information about the jdom-interest mailing list