[jdom-interest] XmlOutputter : escaping of \r in element text

Thomas Fischer Fischer at seitenbau.net
Tue Oct 26 08:01:29 PDT 2004





Hi,

I have a problem concerning the escaping of windows linefeeds in element
texts in JDOM 1.0:
...
Element element = new element("test");
element.setText("test\r\ntest");
...
XMLOutputter outputter = new XMLOutputter();
outputter.output(document, System.out);

The outputter prints the following
<test>test&#xD;
test</test>
while I just want to have
<test>test
test</test>

I do not see how I could achieve this within jdom. Using EscapeStrategy is
of no use, because it is not involved on the \r character (see jdom
sources, XmlOutputter.java, line 1455).

In my opinion, this behaviour only makes sense for the special characters
defined in the xml spec (<">'&), but not for additional entities,
because e.g. the character \r is a perfectly valid character within
a xml document (see the xml specification,
http://www.w3.org/TR/1998/REC-xml-1998021, chapter 2.2).

A solution which would be 'backward compatible' in most cases would be to
change the jdom source such that a "default escape strategy" is used which
escapes the \r and \n character, but which can be overridden.

What do you think ?

   Thomas




More information about the jdom-interest mailing list