Hi all,
I have run into a rather perplexing situation, not sure if anyone can shed some light on this.
I have a webapp that in the course of it's operation uses Xerces-J v2.6.2 to write a short XML file to disk. This file is encoded UTF-8 so that Greek characters and accented characters are supported. This file is then later read back in from disk by the same application, also using Xerces-J.
Using Java v1.4.2 + Tomcat v5.0.28 under Red Hat Linux 3, the saving of the file, and the subsequence loading of the file works 100% fine in the presence of accented characters.
Using Java v1.4.2 + Tomcat v5.0.28 on Windows XP, the saving of the file completes successfully, but the subsequent loading back in of the file fails with a UTFDataFormatException.
Looking at the saved file the error message is 100% correct: The accented character has been written out using ISO-8859-1 encoding instead of UTF-8 as requested. When read back in, the UTF-8 parser sees the ISO-8859-1 character and throws an exception. If you move a file written by the Windows system across to the Linux system, the Linux system throws the same error with the file. If you edit the broken Windows file XML header to say ISO-8859-1 encoding instead of UTF-8, suddenly that file is read back in correctly.
The error seems to be with Xerces writing out an XML file. Under Linux, Xerces writes UTF-8 data correctly. Under Windows however, Xerces outputs ISO-8859-1 instead, even though it has been expressly told to output UTF-8. The code to output the XML is as follows:
Writer writer = new FileWriter(this.workboxFile);
OutputFormat outputFormat = new OutputFormat("xml", "UTF-8", true);
XMLSerializer serial = new XMLSerializer(writer, outputFormat);
serial.asDOMSerializer();
serial.serialize(this.workboxDocument);
writer.close();I've either run into a Xerces bug, or a Java bug, or I have done something stupid. Has anybody on this list run into anything like this before?
Regards, Graham --
smime.p7s
Description: S/MIME Cryptographic Signature
