How to force javax xslt transformer to encode entities in utf-8?

Posted by calavera.info on Stack Overflow See other posts from Stack Overflow or by calavera.info
Published on 2010-06-12T16:51:40Z Indexed on 2010/06/12 17:12 UTC
Read the original article Hit count: 341

Filed under:
|
|
|
|

I'm working on filter that should transform an output with some stylesheet. Important sections of code looks like this:

PrintWriter out = response.getWriter();
...
StringReader sr = new StringReader(content);
Source xmlSource = new StreamSource(sr, requestSystemId);
transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8");
transformer.setParameter("encoding", "UTF-8");
//same result when using ByteArrayOutputStream xo = new java.io.ByteArrayOutputStream();
StringWriter xo = new StringWriter();
StreamResult result = new StreamResult(xo);
transformer.transform(xmlSource, result);
out.write(xo.toString());

The problem is that national characters are encoded as html entities and not by using UTF. Is there any way to force transformer to use UTF-8 instead of entities?

© Stack Overflow or respective owner

Related posts about java

Related posts about xslt