You are viewing a plain text version of this content. The canonical link for it is here.
Posted to fop-users@xmlgraphics.apache.org by Henrik Holle <hh...@megatel.de> on 2002/05/16 16:45:45 UTC

unicode problem

hi,

i have an java string with an greek alpha letter.  i do not know how to
convert the java unicode string so that i can display
it with fop


i need something like:
	<fo:inline  font-family="Symbol"  font-size="7pt">&#x03B1;</fo:inline>


Re: unicode problem

Posted by "J.Pietschmann" <j3...@yahoo.de>.
Henrik Holle wrote:
> i have an java string with an greek alpha letter.  i do not know how to
> convert the java unicode string so that i can display
> it with fop
> i need something like:
> 	<fo:inline  font-family="Symbol"  font-size="7pt">&#x03B1;</fo:inline>

You have at least two options:
1. Let the Java library write a stream in an encoding which
is understood by an XML parser. Look at the documentation for
java.io.OutputStreamWriter for this purpose. Create one with
UTF-8 or perhaps another UTF encoding, like
  w=new java.io.OutputStreamWriter(new FileOutputStream("f.xml"),"UTF-8")
  w.write(theString,0,theString.length());
Be sure to put an XML declaration in front with either
encoding="UTF-8" or no encoding specification at all (UTF-8
can be autodetected). There is an overwiev of character
encoding handling in Java on the package summary for java.lang.

2. Print the XML character references yourself. This isn't hard
(assuming your default character encoding is ASCII or an ASCII
extension like ISO-8859).
  for( int i=0;i<theString.length();i++ ) {
   char c=theString.charAt(i);
   int ci=(int)c;
   if( ci<=127 ) {
    System.out.print(c);
   } else {
    System.out.print("&#"+ci+";");
   }
  }

J.Pietschmann