[prev in list] [next in list] [prev in thread] [next in thread] 

List:       xalan-j-users
Subject:    RE: Problem with non-ascii characters
From:       "Andrew Welch" <AWelch () piper-group ! com>
Date:       2003-04-30 11:12:07
[Download RAW message or body]


> The resulting string has question marks (??) for the shift-jis string.

Hi,

I'm pretty sure java defaults strings to the UTF-16 encoding, so your result will be \
encoded in UTF-16 while you are probably viewing it in UTF-8, therefore will see \
unknown characters (??).

You could try using a ByteArrayOutputStream() as your result, as you can specify the \
encoding.

cheers
andrew  

> 
> Hi,
> 
> I'm having a problem using Xalan with documents with 
> non-ascii characters.
> 
> I do the following where args[0] is a stylesheet with no templates and
> args[1] is a simple XML document with
> encoding="Shift_JIS and a two character shift-jis string:
> 
> transformFactory_ = TransformerFactory.newInstance();
> stylesheet_ = transformFactory_.newTemplates(new 
> StreamSource(args[0]));
> 
> errorHandler_ = new XsltErrorListener();
> transformFactory_.setErrorListener(errorHandler_);
> Reader stream = new FileReader(args[0]);
> Transformer processor = stylesheet_.newTransformer();
> 
> processor.setErrorListener(new XsltErrorListener());
> 
> StringWriter writer = new StringWriter();
> 
> processor.transform(new StreamSource(args[1]),
> new StreamResult(writer));
> 
> System.out.println(writer.getBuffer().toString());
> 
> The resulting string has question marks (??) for the shift-jis string.
> 
> If I process this with org.apache.xalan.xslt.Process I get 
> the shift-jis
> string
> correctly encoded as UTF-8.  As far as I can tell I'm doing 
> the same thing
> that
> the Process class is doing.
> 
> Is there something that I'm doing wrong?
> 
> Thanks,
> Allen
> 
> 
> 
> 
> ---
> Incoming mail is certified Virus Free.
> Checked by AVG anti-virus system (http://www.grisoft.com).
> Version: 6.0.470 / Virus Database: 268 - Release Date: 08/04/2003
> 
> 

---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.470 / Virus Database: 268 - Release Date: 08/04/2003
 


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic