[jdom-interest] XmlOutputter : escaping of \r in element text
Bradley S. Huffman
hip at cs.okstate.edu
Tue Oct 26 09:03:12 PDT 2004
Thomas Fischer writes:
> 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
> test</test>
> while I just want to have
> <test>test
> test</test>
You'll have to do element.setText("test\ntest"), leaving out the \r
> 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).
Read section 2.11 End-of-Line handling and consider round-tripping (going
from a text file, to JDOM, back to a text file). The problem is for JDOM to
ever have a Text node with \r in it, and to ensure that round-tripping works,
then the original text file would have to have used a char. reference like

. Otherwise the \r would have been normalized.
Also see www.jdom.org/pipermail/jdom-interest/2003-July/012558.html
Brad
More information about the jdom-interest
mailing list