You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-users@xalan.apache.org by Henry Zongaro <zo...@ca.ibm.com> on 2004/09/07 16:02:51 UTC

Re: Encoding problem with using SAXSource and Xalan Transformer.

Hi, Laurent.

Laurent ForĂȘt <l....@clipack.com> wrote on 08/25/2004 09:58:42 AM:
> I have a String containing an xml document with iso-8859-1 encoding.
> I would like to transform it 
> without using an xsl but with an XMLFilterImpl.
> 
> Then I have the following code :
> 
> Transformer transformer_ = new org.apache.xalan.processor.
> TransformerFactoryImpl().newTransformer();
 ...
> ByteArrayOutputStream baos = new ByteArrayOutputStream();
> java.io.OutputStreamWriter osw = new java.io.
> OutputStreamWriter(baos,"ISO8859_1");
> logger_.debug("osw encoding :"+osw.getEncoding());
> StreamResult sr = new StreamResult(osw);
> 
> transformer_.transform(source, sr);
> 
> 
> I have for a result an xml with the default encoding UTF-8 instead 
> the one I expect, I mean 
> iso-8859-1. I have the same result even if I don't use the filter 
> (see the commented line).

     The Transformer object does not check the output encoding specified 
on the OutputStream contained in the StreamResult object - it's guided 
entirely by the output properties specified either in the stylesheet or on 
the Transformer object.  You can try setting the encoding output property 
on the Transformer object as follows:

  transformer.setOutputProperty(
      javax.xml.transform.OutputKeys.ENCODING,
      "ISO8859_1");

I hope that helps.

Thanks,

Henry
------------------------------------------------------------------
Henry Zongaro      Xalan development
IBM SWS Toronto Lab   T/L 969-6044;  Phone +1 905 413-6044
mailto:zongaro@ca.ibm.com