[jdom-interest] Use ampersand character in setText

Robin Rosenberg robin.rosenberg.lists at dewire.com
Fri Dec 16 08:51:02 PST 2011


Andrea Pacini skrev 2011-12-16 10.43:
> Hi,
> according to Jdom FAQ ( http://www.jdom.org/docs/faq.html#a0290 ) , I tried to write the string
>
> &test
>
> using this statement:
>
> root.setText("\u0026test");
>
> where \u0026 is the Unicode code for ampersand character.
>
> The output is:
>
> &test
>
> Where is the error ?

It's in your interpretation/the writing in the FAQ.

It should be more like "Why does setText(" ") not output a NO-BREAK SPACE
character into the XML document".

There is no difference in Java between "&test" and "\u0026test", except that the
latter is harder to read. Both translates into the exact same bytecode.

The FAQ could be complemented with the corrected call, e.g. setText("\u00a0"); To make
things more confusing Java uses hexadecimal code units while XML uses decimal code points.

-- robin


More information about the jdom-interest mailing list