lundi 20 juillet 2015

Unable to translate portuguese characters that is part of a name in XML String

I am facing trouble in translating portuguese characters that is part of a field in XML String. I am using the transform Method and also encoded with iso-8859-1 and i ended up in

javax.xml.transform.TransformerException: com.sun.org.apache.xml.internal.utils.WrappedRuntimeException: Invalid byte 2 of 3-byte UTF-8 sequence.

Here is the code i am using.

String transformedMessage = "";

ByteArrayInputStream bais = null;
try {
    bais = new ByteArrayInputStream(
            inputMessage.getBytes("iso-8859-1"));
} catch (UnsupportedEncodingException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
}
StreamSource xsltSource = new StreamSource(
        new ByteArrayInputStream(xsltTemplate.getBytes()));

StreamSource source = new StreamSource(bais,"iso-8859-1");
ByteArrayOutputStream baos = new ByteArrayOutputStream();
StreamResult result = new StreamResult(baos);

TransformerFactory factory = TransformerFactory.newInstance();
Transformer transformer = factory.newTransformer(xsltSource);

transformer.transform(source, result);
transformedMessage = baos.toString();

return transformedMessage;

inputMessage has the Name tag with the name "Olá", whcih is in portuguese . The same code is working if we send Chinese and Thai Characters. Can you please help me with this error.

Aucun commentaire:

Enregistrer un commentaire