  | |  | problem with DOM and Encoding | problem with DOM and Encoding 2004-02-25 - By Markus Jais
hi
I have 2 different methods for outputting a DOM Tree:
Methode 1: (DOM 3 / Xerces 2.4) =========== public String toXML2() throws RPCException ��������{ ����������������String��������������ret�=�"UNO"; ����������������DOMWriter�writer�=�null; ���������������� ����������������try�{ ������������������������writer�=�((DOMImplementationLS)this.implementation) .createDOMWriter(); ������������������������writer.setEncoding("ISO-8859-1"); ������������������������ret�+=�writer.writeToString(document); ����������������}�catch�(DOMException�domex)�{ ������������������������; ����������������} ����������������return�ret; ���������������� ��������} ��������
Methode 2: (JAXP + TRAX with Xerces 2.4) ============ public String toXML() throws RPCException ��������{ ����������������String�ret�=�"DOS"; ����������������try�{ ������������������������TransformerFactory�transFactory�=�TransformerFactory .newInstance(); ������������������������Transformer�transformer�=�transFactory.newTransformer(); ������������������������Source�input�=�new�DOMSource(document); ������������������������StringWriter�strWriter�=�new�StringWriter(); ������������������������Result�output�=�new�StreamResult(strWriter);���� ������������������������transformer.setOutputProperty(OutputKeys.ENCODING,�"ISO -8859-1"); ������������������������transformer.transform(input,�output); ������������������������ret�+=�strWriter.toString(); ������������������������try�{ ��������������������������������strWriter.close(); ������������������������}�catch�(IOException�ex)�{ ��������������������������������throw�new�RPCException("Error�closing�String �Writer"); ������������������������} ������������������������return�ret; ������������������������ ����������������}�catch�(TransformerConfigurationException�ex)�{ ������������������������; ����������������}�catch�(TransformerException�ex)�{ ������������������������; ����������������} ���������������� ��������}
both return a string method 1 turns "M�nchen" into:�� M�nchen
and method 2 into M�nchen
(If your news reader does not display german umlauts: in HTML you would write "München")
it seems that both encodings are wrong and also different. this is weird. I also did a
export LANG=de_DE
no changes although within my JBOSS message driven bean it works with this variable set.
I have Suse Linux 8.2 and java version "1.4.2_03"
any ideas what's wrong here ?
Markus -- Markus Jais Software Developer GMX GmbH Riesstra�e 17, 80992 M�nchen Phone: +49 89 14 339-514 mailto:mjais@(protected) http://www.gmx.de
--------------------------------------------------------------------- To unsubscribe, e-mail: xerces-j-user-unsubscribe@(protected) For additional commands, e-mail: xerces-j-user-help@(protected)
|
|
 |