* Dario Di Bella wrote in comp.text.xml:
Basically what I want to do is to print that CDATA section in an HTML
page, using a jsp custom tag.
To make that work you need to ensure that the HTML document and the
output of your code use the same encoding. It's all about the bytes.
You could try to copy and paste the following fragment into a HTML
document
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN">
<meta http-equiv=Content-Type content="text/html;charset=utf-8">
<title></title>
<p>» AttivitÃ* Promotore</p>
and load that into your browser. All your characters should be just
fine. If you change the fragment to
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN">
<meta http-equiv=Content-Type content="text/html;charset=iso-8859-1">
<title></title>
<p>» AttivitÃ* Promotore</p>
It breaks. So you need to either change the encoding and/or
declaration of the encoding of the surrounding HTML document
or you need to transcode the data or you can try to use character
references.
The java.lang.String object for example provides a getBytes(...)
method, you can do e.g. the following:
class Foo{public static void main(String[] argv){try{
System.out.write("\u00f6".getBytes("UTF-8"));
System.out.println();
System.out.write("\u00f6".getBytes("ISO-8859-1"));
System.out.println();
System.out.write(0x94); /* CP850, but it is not supported... */
System.out.println();
} catch (Exception e) {e.printStackTrace();}}}
Depending on your operating system, locales, etc. one of the writes
will most likely show an "ö". If you work on Windows, on the command
line most likely the last write(), if you redirect the output to a
file (`java Foo > file.txt`) and open file.txt in Notepad, you would
notice that it is now the second write() that shows the "ö". You can
also create a new text file containing "ö" and go to the command line
prompt and type "type C:\...\file.txt" which would then likely show
"÷" not "ö".
HTH...